Skip to content

Commit

Permalink
stream: 'data' argument on callback of Transform._flush()
Browse files Browse the repository at this point in the history
Add a `data` argument on Transform._flush() callback to be API consistent with Transform._transform().

Fixes: #3707
  • Loading branch information
piranna committed Jun 7, 2016
1 parent 671cffa commit 1f238f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.

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);
});

0 comments on commit 1f238f6

Please sign in to comment.