Skip to content

Commit

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

PR-URL: #36479
Backport-PR-URL: #36831
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 BethGriggs committed Jan 28, 2021
1 parent 9c438b5 commit 2a1e4e9
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
Expand Up @@ -142,7 +142,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
Expand Up @@ -1216,3 +1216,19 @@ const net = require('net');
assert.strictEqual(res, 'helloworld');
}));
}

{
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 2a1e4e9

Please sign in to comment.