Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'data' argument on callback of Transform._flush() #3708

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions lib/_stream_transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-stream-transform-flush-data.js
Original file line number Diff line number Diff line change
@@ -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);
});