Skip to content

Commit 2a1e4e9

Browse files
LxxyxBethGriggs
authored andcommitted
stream: accept iterable as a valid first argument
Fixes: #36437 PR-URL: #36479 Backport-PR-URL: #36831 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 9c438b5 commit 2a1e4e9

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
@@ -142,7 +142,10 @@ async function pump(iterable, writable, finish) {
142142
function pipeline(...streams) {
143143
const callback = once(popCallback(streams));
144144

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

147150
if (streams.length < 2) {
148151
throw new ERR_MISSING_ARGS('streams');

test/parallel/test-stream-pipeline.js

+16
Original file line numberDiff line numberDiff line change
@@ -1216,3 +1216,19 @@ const net = require('net');
12161216
assert.strictEqual(res, 'helloworld');
12171217
}));
12181218
}
1219+
1220+
{
1221+
pipeline([1, 2, 3], PassThrough({ objectMode: true }),
1222+
common.mustSucceed(() => {}));
1223+
1224+
let res = '';
1225+
const w = new Writable({
1226+
write(chunk, encoding, callback) {
1227+
res += chunk;
1228+
callback();
1229+
},
1230+
});
1231+
pipeline(['1', '2', '3'], w, common.mustSucceed(() => {
1232+
assert.strictEqual(res, '123');
1233+
}));
1234+
}

0 commit comments

Comments
 (0)