summaryrefslogtreecommitdiff
path: root/node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js
diff options
context:
space:
mode:
authorakiyamn2023-09-24 23:22:21 +1000
committerakiyamn2023-09-24 23:22:21 +1000
commit4e87195739f2a5d9a05451b48773c8afdc680765 (patch)
tree9cba501844a4a11dcbdffc4050ed8189561c55ed /node_modules/rollup-plugin-node-polyfills/polyfills/readable-stream/duplex.js
downloadprice-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.tar.gz
price-tracker-worker-4e87195739f2a5d9a05451b48773c8afdc680765.zip
Initial commit (by create-cloudflare CLI)
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.js45
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();
+}