Skip to content

Commit

Permalink
stream: use ByteLengthQueuingStrategy when not in object mode (fixes n…
Browse files Browse the repository at this point in the history
  • Loading branch information
CGQAQ committed Jul 21, 2023
1 parent aa262b2 commit 74ada82
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions lib/internal/webstreams/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {

const {
CountQueuingStrategy,
ByteLengthQueuingStrategy,
} = require('internal/webstreams/queuingstrategies');

const {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(); },
Expand Down

0 comments on commit 74ada82

Please sign in to comment.