Skip to content

Commit 1f238f6

Browse files
committed
stream: 'data' argument on callback of Transform._flush()
Add a `data` argument on Transform._flush() callback to be API consistent with Transform._transform(). Fixes: nodejs#3707
1 parent 671cffa commit 1f238f6

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

deps/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream/doc/stream.markdown

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/_stream_transform.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ function Transform(options) {
115115

116116
this.once('prefinish', function() {
117117
if (typeof this._flush === 'function')
118-
this._flush(function(er) {
119-
done(stream, er);
118+
this._flush(function(er, data) {
119+
done(stream, er, data);
120120
});
121121
else
122122
done(stream);
@@ -173,10 +173,13 @@ Transform.prototype._read = function(n) {
173173
};
174174

175175

176-
function done(stream, er) {
176+
function done(stream, er, data) {
177177
if (er)
178178
return stream.emit('error', er);
179179

180+
if (data !== null && data !== undefined)
181+
stream.push(data);
182+
180183
// if there's nothing in the write buffer, then that means
181184
// that nothing more will ever be provided
182185
var ws = stream._writableState;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
const assert = require('assert');
6+
const Transform = require('stream').Transform;
7+
8+
9+
const expected = 'asdf';
10+
11+
12+
function _transform(d, e, n) {
13+
n();
14+
}
15+
function _flush(n) {
16+
n(null, expected);
17+
}
18+
19+
var t = new Transform({
20+
transform: _transform,
21+
flush: _flush
22+
});
23+
24+
t.end(Buffer.from('blerg'));
25+
t.on('data', (data) => {
26+
assert.strictEqual(data.toString(), expected);
27+
});

0 commit comments

Comments
 (0)