diff --git a/deps/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/doc/stream.markdown b/deps/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/doc/stream.markdown index 0bc3819e63b025..6922c8cb89faa1 100644 --- a/deps/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/doc/stream.markdown +++ b/deps/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/doc/stream.markdown @@ -1146,7 +1146,7 @@ has been called. #### transform.\_flush(callback) * `callback` {Function} Call this function (optionally with an error - argument) when you are done flushing any remaining data. + argument and data) when you are done flushing any remaining data. Note: **This function MUST NOT be called directly.** It MAY be implemented by child classes, and if so, will be called by the internal Transform diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index 50fc542b5abd91..5dc7fdd0a8d831 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -115,8 +115,8 @@ function Transform(options) { this.once('prefinish', function() { if (typeof this._flush === 'function') - this._flush(function(er) { - done(stream, er); + this._flush(function(er, data) { + done(stream, er, data); }); else done(stream); @@ -173,10 +173,13 @@ Transform.prototype._read = function(n) { }; -function done(stream, er) { +function done(stream, er, data) { if (er) return stream.emit('error', er); + if (data !== null && data !== undefined) + stream.push(data); + // if there's nothing in the write buffer, then that means // that nothing more will ever be provided var ws = stream._writableState; diff --git a/test/parallel/test-stream-transform-flush-data.js b/test/parallel/test-stream-transform-flush-data.js new file mode 100644 index 00000000000000..dede64ba10f9da --- /dev/null +++ b/test/parallel/test-stream-transform-flush-data.js @@ -0,0 +1,27 @@ +'use strict'; + +require('../common'); + +const assert = require('assert'); +const Transform = require('stream').Transform; + + +const expected = 'asdf'; + + +function _transform(d, e, n) { + n(); +} +function _flush(n) { + n(null, expected); +} + +var t = new Transform({ + transform: _transform, + flush: _flush +}); + +t.end(Buffer.from('blerg')); +t.on('data', (data) => { + assert.strictEqual(data.toString(), expected); +});