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

Simpler stream construction #108

Closed
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ function Readable(options) {
// legacy
this.readable = true;

if (options && util.isFunction(options.read))
this._read = options.read;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm -0 on adding this if it's a shorthand for _read = fn – accepting functions into the constructor is a natural jumping off point for the other changes we'd like to see with streams, and if we don't take that opportunity when we add this functionality we'll have lost the chance to do so in the future (this roughly echoes my position from the other issue.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh so you were suggest jump straight to 'start' & 'pull'?

Stream.call(this);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ function Transform(options) {
// sync guard flag.
this._readableState.sync = false;

if (options) {
if (util.isFunction(options.transform))
this._transform = options.transform;

if (util.isFunction(options.flush))
this._flush = options.flush;
}

this.once('prefinish', function() {
if (util.isFunction(this._flush))
this._flush(function(er) {
Expand Down
8 changes: 8 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ function Writable(options) {
// legacy.
this.writable = true;

if (options) {
if (util.isFunction(options.write))
this._write = options.write;

if (util.isFunction(options.writev))
this._writev = options.writev;
}

Stream.call(this);
}

Expand Down