//Duplex stream constructor function Duplex(options) { if(!(this instanceof Duplex)){ return new Duplex(option); } //run through both Readable and Writable stream constructor to construct both parts of them in an instance of Duplex. Readable.call(this, options); Writable.call(this, options); if(options && options.readable === false){ this.readable = false; } if(options && options.writable === false){ this.writable = false; } //by default., Duplex allows half open. this.allowHalfOpen = true; if(options && options.allowHalfOpen === false){ this.allowHalfOpen = false; } //register a once listener on its Readable part's 'end' event. this.once('end', onend); }
function Duplex(options) { if (!(this instanceof Duplex)) return new Duplex(options); Readable.call(this, options); Writable.call(this, options); this.allowHalfOpen = true; if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; this.once('end', onend); }
function TestWritable(opt) { if (!(this instanceof TestWritable)) return new TestWritable(opt); Writable.call(this, opt); this._written = []; }