stream: accept iterable as a valid first argument

Fixes: https://github.com/nodejs/node/issues/36437

PR-URL: https://github.com/nodejs/node/pull/36479
Backport-PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
ZiJian Liu authored and Beth Griggs committed 2021-01-28 17:56:03 +00:00
1 parent 9c438b5ae0
commit 2a1e4e9244
2 files changed
+20 -1

No files matched your search

+4 -1
View File
@@ -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');
+16
View File
@@ -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');
}));
}