mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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:
parent
e0730eeaa5
commit
50daee7243
7 changed files with 175 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue