From 2a1e4e9244a1183cd2155a4d2261a3c24dcacc34 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 Backport-PR-URL: https://github.com/nodejs/node/pull/36831 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 f9b33ed9bda62a..297606dfb84749 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -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'); diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index ac2ea9ab663312..7cfdc4f4141571 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -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'); + })); +}