From 2585b814b0da4895b156e486351fa740910068b7 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 2 Mar 2020 12:44:42 +0100 Subject: [PATCH] stream: add comments to pipeline implementation Fixes: https://github.com/nodejs/node/issues/32039 PR-URL: https://github.com/nodejs/node/pull/32042 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/internal/streams/pipeline.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index df0d7bc85d366c..b03c4e1513925b 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -219,6 +219,11 @@ function pipeline(...streams) { PassThrough = require('_stream_passthrough'); } + // If the last argument to pipeline is not a stream + // we must create a proxy stream so that pipeline(...) + // always returns a stream which can be further + // composed through `.pipe(stream)`. + const pt = new PassThrough(); if (isPromise(ret)) { ret @@ -253,6 +258,9 @@ function pipeline(...streams) { } } + // TODO(ronag): Consider returning a Duplex proxy if the first argument + // is a writable. Would improve composability. + // See, https://github.com/nodejs/node/issues/32020 return ret; }