Skip to content

Commit

Permalink
stream: accept iterable as a valid first argument
Browse files Browse the repository at this point in the history
Fixes: #36437

PR-URL: #36479
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
Lxxyx authored and nodejs-github-bot committed Dec 15, 2020
1 parent 45dbcbe commit 6837a6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ async function pump(iterable, writable, finish) {
function pipeline(...streams) {
const callback = once(popCallback(streams));

if (ArrayIsArray(streams[0])) streams = streams[0];
// stream.pipeline(streams, callback)
if (ArrayIsArray(streams[0]) && streams.length === 1) {
streams = streams[0];
}

if (streams.length < 2) {
throw new ERR_MISSING_ARGS('streams');
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,19 @@ const net = require('net');
});
const pipelined = addAbortSignal(ac.signal, pipeline([r, w], cb));
}

{
pipeline([1, 2, 3], PassThrough({ objectMode: true }),
common.mustSucceed(() => {}));

let res = '';
const w = new Writable({
write(chunk, encoding, callback) {
res += chunk;
callback();
},
});
pipeline(['1', '2', '3'], w, common.mustSucceed(() => {
assert.strictEqual(res, '123');
}));
}

0 comments on commit 6837a6d

Please sign in to comment.