diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 6752519225..53f3171e0b 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -57,6 +57,7 @@ require('inherits')(Duplex, Readable); function Duplex(options) { if (!(this instanceof Duplex)) return new Duplex(options); + this.isDuplex = true Readable.call(this, options); Writable.call(this, options); this.allowHalfOpen = true; diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 192d451488..2b54f27a6a 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -21,10 +21,6 @@ 'use strict'; module.exports = Readable; -/**/ - -var Duplex; -/**/ Readable.ReadableState = ReadableState; /**/ @@ -103,16 +99,14 @@ function prependListener(emitter, event, fn) { if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; } -function ReadableState(options, stream, isDuplex) { - Duplex = Duplex || require('./_stream_duplex'); +function ReadableState(options,isDuplex) { options = options || {}; // Duplex streams are both readable and writable, but share // the same options object. // However, some cases require setting options to different // values for the readable and the writable sides of the duplex stream. // These options can be provided separately as readableXXX and writableXXX. - if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to - // make all the buffer merging and length checks go away + // make all the buffer merging and length checks go away this.objectMode = !!options.objectMode; if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer @@ -167,12 +161,11 @@ function ReadableState(options, stream, isDuplex) { } function Readable(options) { - Duplex = Duplex || require('./_stream_duplex'); + if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside // the ReadableState constructor, at least with V8 6.5 - - var isDuplex = this instanceof Duplex; - this._readableState = new ReadableState(options, this, isDuplex); // legacy + + this._readableState = new ReadableState(options, this.isDuplex); // legacy this.readable = true;