diff options
author | isaacs <i@izs.me> | 2013-03-03 19:05:44 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-03-05 14:27:15 -0800 |
commit | cd68d86c3283af2f4b3c349c2081c609e3978b9b (patch) | |
tree | 1ac21569c2bf81e1d2cdbb5d6a0236bfd89c0833 /lib/_stream_transform.js | |
parent | 049903e333f843d7587e7c40845a7d51ea5955f8 (diff) | |
download | node-new-cd68d86c3283af2f4b3c349c2081c609e3978b9b.tar.gz |
stream: Remove output function from _transform
Just use stream.push(outputChunk) instead.
Diffstat (limited to 'lib/_stream_transform.js')
-rw-r--r-- | lib/_stream_transform.js | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index d8f6e60532..222b1390f8 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -71,10 +71,6 @@ util.inherits(Transform, Duplex); function TransformState(options, stream) { var ts = this; - this.output = function(chunk) { - ts.needTransform = false; - stream.push(chunk); - }; this.afterTransform = function(er, data) { return afterTransform(stream, er, data); @@ -99,7 +95,7 @@ function afterTransform(stream, er, data) { ts.writecb = null; if (data !== null && data !== undefined) - ts.output(data); + stream.push(data); if (cb) cb(er); @@ -132,7 +128,7 @@ function Transform(options) { this.once('finish', function() { if ('function' === typeof this._flush) - this._flush(ts.output, function(er) { + this._flush(function(er) { done(stream, er); }); else @@ -140,12 +136,17 @@ function Transform(options) { }); } +Transform.prototype.push = function(chunk) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk); +}; + // This is the part where you do stuff! // override this function in implementation classes. // 'chunk' is an input chunk. // -// Call `output(newChunk)` to pass along transformed output -// to the readable side. You may call 'output' zero or more times. +// Call `push(newChunk)` to pass along transformed output +// to the readable side. You may call 'push' zero or more times. // // Call `cb(err)` when you are done with this chunk. If you pass // an error, then that'll put the hurt on the whole operation. If you @@ -158,11 +159,13 @@ Transform.prototype._write = function(chunk, cb) { var ts = this._transformState; ts.writecb = cb; ts.writechunk = chunk; - if (ts.transforming) - return; - var rs = this._readableState; - if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) - this._read(rs.bufferSize); + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || + rs.needReadable || + rs.length < rs.highWaterMark) + this._read(rs.bufferSize); + } }; // Doesn't matter what the args are here. @@ -173,13 +176,12 @@ Transform.prototype._read = function(n) { if (ts.writechunk && ts.writecb && !ts.transforming) { ts.transforming = true; - this._transform(ts.writechunk, ts.output, ts.afterTransform); - return; + this._transform(ts.writechunk, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; } - - // mark that we need a transform, so that any data that comes in - // will get processed, now that we've asked for it. - ts.needTransform = true; }; |