stream: simpler stream constructon

Adds simplified constructor pattern, allowing users
to provide "read", "write", "transform", "flush", and
"writev" functions as stream options in lieu of subclassing.

Semver: minor
PR-URL: https://github.com/iojs/io.js/pull/697
Fixes: https://github.com/iojs/readable-stream/issues/102
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
This commit is contained in:
Sam Newman 2015-02-03 01:12:41 +00:00 committed by Chris Dickinson
parent e0730eeaa5
commit 50daee7243
7 changed files with 175 additions and 2 deletions

View file

@ -105,6 +105,14 @@ function Transform(options) {
// sync guard flag.
this._readableState.sync = false;
if (options) {
if (typeof options.transform === 'function')
this._transform = options.transform;
if (typeof options.flush === 'function')
this._flush = options.flush;
}
this.once('prefinish', function() {
if (typeof this._flush === 'function')
this._flush(function(er) {