You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, teeing a readable byte stream always returns two "default" readable streams. This prevents developers from using a BYOB reader on a tee'd byte stream.
I think we should change ReadableStreamTee to return two readable byte streams when given a readable byte stream as its input. This should also help with e.g. whatwg/fetch#267: when we make Response.body a readable byte stream, we need to make sure that Response.clone() creates two new byte streams as well.
Use CreateReadableByteStream instead of CreateReadableStream for creating the two branches. (Note that this abstract op was removed in Rewrite to use Web IDL, and generally modernize #1035 because it was unused, but it shouldn't be difficult to bring it back.)
Use the ReadableByteStreamController and its abstract ops instead of a ReadableStreamDefaultController.
Clone every read chunk, and enqueue the original chunk and the cloned chunk to the two branches. (If one of the two branches is already cancelled, we don't need to clone the chunk.)
Note that such an implementation would still use a ReadableStreamDefaultReader to read the byte chunks. This means any BYOB request from a tee'd stream cannot reach the original stream, so the original stream must always allocate a new buffer for every chunk and cannot make an informed decision on how big that buffer should be. It may be worth investigating if we can switch to a ReadableStreamBYOBReader inside the teeing logic whenever a tee'd branch has a pending BYOB request.
The text was updated successfully, but these errors were encountered:
Currently, teeing a readable byte stream always returns two "default" readable streams. This prevents developers from using a BYOB reader on a tee'd byte stream.
I think we should change
ReadableStreamTee
to return two readable byte streams when given a readable byte stream as its input. This should also help with e.g. whatwg/fetch#267: when we makeResponse.body
a readable byte stream, we need to make sure thatResponse.clone()
creates two new byte streams as well.An easy solution would be to start from the current
ReadableStreamTee
abstract op, and adapt it a bit:CreateReadableByteStream
instead ofCreateReadableStream
for creating the two branches. (Note that this abstract op was removed in Rewrite to use Web IDL, and generally modernize #1035 because it was unused, but it shouldn't be difficult to bring it back.)ReadableByteStreamController
and its abstract ops instead of aReadableStreamDefaultController
.Note that such an implementation would still use a
ReadableStreamDefaultReader
to read the byte chunks. This means any BYOB request from a tee'd stream cannot reach the original stream, so the original stream must always allocate a new buffer for every chunk and cannot make an informed decision on how big that buffer should be. It may be worth investigating if we can switch to aReadableStreamBYOBReader
inside the teeing logic whenever a tee'd branch has a pending BYOB request.The text was updated successfully, but these errors were encountered: