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
  • Loading branch information
Lxxyx committed Dec 11, 2020
commit 86d8a8f151fa282f6d0fe524f58ee1fa0c3f213d
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');
}));
}