From c374648abf6f06bec80494a972c7ddce31a5444b 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 --- 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 8c6cbf7524ea53..dda8396645bdcc 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -188,6 +188,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 @@ -222,6 +227,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; }