mirror of https://github.com/nodejs/node.git
stream: 'data' argument on callback of Transform._flush()
Add a `data` argument on Transform._flush() callback to be API consistent with Transform._transform(). Fixes: https://github.com/nodejs/node/issues/3707 PR-URL: https://github.com/nodejs/node/pull/3708 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>pull/6863/merge
parent
779091ffdb
commit
0cd0118334
|
@ -1697,7 +1697,7 @@ after all data has been output, which occurs after the callback in
|
|||
#### transform.\_flush(callback)
|
||||
|
||||
* `callback` {Function} A callback function (optionally with an error
|
||||
argument) to be called when remaining data has been flushed.
|
||||
argument and data) to be called when remaining data has been flushed.
|
||||
|
||||
*Note*: **This function MUST NOT be called by application code directly.** It
|
||||
should be implemented by child classes, and called only by the internal Readable
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
Loading…
Reference in New Issue