Skip to content

Commit f58c5ba

Browse files
mcollinaaduh95
authored andcommitted
stream: fix Writable.toWeb() desiredSize for non-object-mode
Writable.toWeb() used a plain { highWaterMark } as the queuing strategy for non-object-mode streams, which meant no size function was provided. The WritableStream defaulted to counting each chunk as size 1, so desiredSize was incorrect (e.g., a 3-byte Uint8Array was counted as size 1 instead of 3). Add a size() function to the strategy that mirrors how the Node.js stream computes chunk length: byteLength for typed arrays, length for strings/buffers, falling back to 1. Fixes: #56269 Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #62986 Reviewed-By: René <contact.9a5d6388@renegade334.me.uk> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent a56fbb2 commit f58c5ba

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎lib/internal/webstreams/adapters.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ function newWritableStreamFromStreamWritable(streamWritable, options = kEmptyObj
179179
conststrategy=
180180
streamWritable.writableObjectMode ?
181181
newCountQueuingStrategy({ highWaterMark }) :
182-
{ highWaterMark };
182+
{
183+
highWaterMark,
184+
size(chunk){
185+
returnchunk?.byteLength??chunk?.length??1;
186+
},
187+
};
183188

184189
letcontroller;
185190
letbackpressurePromise;

0 commit comments

Comments
 (0)