diff options
Diffstat (limited to 'node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js')
| -rw-r--r-- | node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js b/node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js new file mode 100644 index 0000000..ecc01a7 --- /dev/null +++ b/node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js @@ -0,0 +1,45 @@ + +import {inherits} from 'util'; +import {nextTick} from 'process'; +import {Readable} from './readable'; +import {Writable} from './writable'; + + +inherits(Duplex, Readable); + +var keys = Object.keys(Writable.prototype); +for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; +} +export default Duplex; +export function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + + Readable.call(this, options); + Writable.call(this, options); + + if (options && options.readable === false) this.readable = false; + + if (options && options.writable === false) this.writable = false; + + this.allowHalfOpen = true; + if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; + + this.once('end', onend); +} + +// the no-half-open enforcer +function onend() { + // if we allow half-open state, or if the writable side ended, + // then we're ok. + if (this.allowHalfOpen || this._writableState.ended) return; + + // no more data can be written. + // But allow more writes to happen in this tick. + nextTick(onEndNT, this); +} + +function onEndNT(self) { + self.end(); +} |
