Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circular dependency #458

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ require('inherits')(Duplex, Readable);

function Duplex(options) {
if (!(this instanceof Duplex)) return new Duplex(options);
Readable.call(this, options);
Writable.call(this, options);
Readable.call(this, options, true);
Writable.call(this, options, true);
this.allowHalfOpen = true;

if (options) {
15 changes: 4 additions & 11 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
@@ -21,10 +21,6 @@
'use strict';

module.exports = Readable;
/*<replacement>*/

var Duplex;
/*</replacement>*/

Readable.ReadableState = ReadableState;
/*<replacement>*/
@@ -104,16 +100,12 @@ function prependListener(emitter, event, fn) {
}

function ReadableState(options, stream, isDuplex) {
Duplex = Duplex || require('./_stream_duplex');
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

this.objectMode = !!options.objectMode;
if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
// Note: 0 is a valid value, means "don't call _read preemptively ever"
@@ -166,12 +158,13 @@ function ReadableState(options, stream, isDuplex) {
}
}

function Readable(options) {
Duplex = Duplex || require('./_stream_duplex');
function Readable(options, isDuplex) {
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;
if (typeof isDuplex !== 'boolean') isDuplex = false; // object stream flag. Used to make read(n) ignore n and to
// make all the buffer merging and length checks go away

this._readableState = new ReadableState(options, this, isDuplex); // legacy

this.readable = true;
18 changes: 5 additions & 13 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
@@ -47,12 +47,6 @@ function CorkedRequest(state) {
}
/* </replacement> */

/*<replacement>*/


var Duplex;
/*</replacement>*/

Writable.WritableState = WritableState;
/*<replacement>*/

@@ -101,16 +95,12 @@ require('inherits')(Writable, Stream);
function nop() {}

function WritableState(options, stream, isDuplex) {
Duplex = Duplex || require('./_stream_duplex');
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,
// e.g. options.readableObjectMode vs. options.writableObjectMode, etc.

if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
// contains buffers or objects.

this.objectMode = !!options.objectMode;
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
// Note: 0 is a valid value, means that we always return false if
@@ -226,8 +216,8 @@ if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.protot
};
}

function Writable(options) {
Duplex = Duplex || require('./_stream_duplex'); // Writable ctor is applied to Duplexes, too.
function Writable(options, isDuplex) {
// Writable ctor is applied to Duplexes, too.
// `realHasInstance` is necessary because using plain `instanceof`
// would return false, as no `_writableState` property is attached.
// Trying to use the custom `instanceof` for Writable here will also break the
@@ -236,7 +226,9 @@ function Writable(options) {
// Checking for a Stream.Duplex instance is faster here instead of inside
// the WritableState constructor, at least with V8 6.5

var isDuplex = this instanceof Duplex;
if (typeof isDuplex !== 'boolean') isDuplex = false; // object stream flag to indicate whether or not this stream
// contains buffers or objects.

if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
this._writableState = new WritableState(options, this, isDuplex); // legacy.