From c5c66b4f1bfa2cbc26137618ac3910ca24bfc9a0 Mon Sep 17 00:00:00 2001 From: CGQAQ Date: Fri, 21 Jul 2023 04:38:37 +0000 Subject: [PATCH] stream: use ByteLengthQueuingStrategy when not in object mode (fixes #46347) --- lib/internal/webstreams/adapters.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index ec39656738e9ea..dab84a740fc51b 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -25,6 +25,7 @@ const { const { CountQueuingStrategy, + ByteLengthQueuingStrategy, } = require('internal/webstreams/queuingstrategies'); const { @@ -417,11 +418,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj return new CountQueuingStrategy({ highWaterMark }); } - // When not running in objectMode explicitly, we just fall - // back to a minimal strategy that just specifies the highWaterMark - // and no size algorithm. Using a ByteLengthQueuingStrategy here - // is unnecessary. - return { highWaterMark }; + return new ByteLengthQueuingStrategy({ highWaterMark }); }; const strategy = evaluateStrategyOrFallback(options?.strategy); @@ -457,12 +454,6 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj streamReadable.on('data', onData); return new ReadableStream({ - // CGQAQ: we know that `Readable.readableHighWaterMark - // size is always in bytes, so we can use `bytes` here - // to make the `ReadableStream` a byte stream. - // Ref: https://streams.spec.whatwg.org/#high-water-mark:~:text=Concretely%2C%20a%20queuing,floating%2Dpoint%20units. - type: 'bytes', - start(c) { controller = c; }, pull() { streamReadable.resume(); },