Skip to content

Commit d8b5b94

Browse files
Lxxyxtargos
authored andcommitted
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>
1 parent 728f512 commit d8b5b94

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/internal/streams/pipeline.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ async function pump(iterable, writable, finish) {
144144
function pipeline(...streams) {
145145
const callback = once(popCallback(streams));
146146

147-
if (ArrayIsArray(streams[0])) streams = streams[0];
147+
// stream.pipeline(streams, callback)
148+
if (ArrayIsArray(streams[0]) && streams.length === 1) {
149+
streams = streams[0];
150+
}
148151

149152
if (streams.length < 2) {
150153
throw new ERR_MISSING_ARGS('streams');

test/parallel/test-stream-pipeline.js

+16
Original file line numberDiff line numberDiff line change
@@ -1285,3 +1285,19 @@ const net = require('net');
12851285
});
12861286
const pipelined = addAbortSignal(ac.signal, pipeline([r, w], cb));
12871287
}
1288+
1289+
{
1290+
pipeline([1, 2, 3], PassThrough({ objectMode: true }),
1291+
common.mustSucceed(() => {}));
1292+
1293+
let res = '';
1294+
const w = new Writable({
1295+
write(chunk, encoding, callback) {
1296+
res += chunk;
1297+
callback();
1298+
},
1299+
});
1300+
pipeline(['1', '2', '3'], w, common.mustSucceed(() => {
1301+
assert.strictEqual(res, '123');
1302+
}));
1303+
}

0 commit comments

Comments
 (0)