Skip to content
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
stream: accept iterable as a valid first argument
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 voxpelli committed Jan 7, 2021
commit 9f2a7dfe57d83ee391d388be7a6242f6b7922277
5 changes: 4 additions & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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');
}));
}