From 6837a6de9760fcff8ad106009538b0c5cebd1967 Mon Sep 17 00:00:00 2001 From: ZiJian Liu Date: Fri, 11 Dec 2020 22:11:14 +0800 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott Reviewed-By: Antoine du Hamel --- lib/internal/streams/pipeline.js | 5 ++++- test/parallel/test-stream-pipeline.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index b23f05ca1f206a..89561433c8c132 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -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'); diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index f4801ece268a5b..78057f9eeffec6 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -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'); + })); +}