UNPKG

@thewtex/vtk.js-esm

Version:

Visualization Toolkit for the Web

45 lines (33 loc) 1.3 kB
import { u as util } from '../vendor/util/util.js'; import { b as browser } from '../vendor/process/browser.js'; import { R as Readable } from './polyfill-node__stream_readable.js'; import { W as Writable } from './polyfill-node__stream_writable.js'; util.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]; } 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. browser.nextTick(onEndNT, this); } function onEndNT(self) { self.end(); } export { Duplex as D };