From 4e87195739f2a5d9a05451b48773c8afdc680765 Mon Sep 17 00:00:00 2001 From: akiyamn Date: Sun, 24 Sep 2023 23:22:21 +1000 Subject: Initial commit (by create-cloudflare CLI) --- .../polyfills/readable-stream/duplex.js | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js (limited to 'node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js') 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(); +} -- cgit v1.2.3