PSA: Support for teeing readable byte streams

26 views
Skip to first unread message

Nidhi Jaju

unread,
Apr 13, 2023, 1:52:05 AM4/13/23
to blin...@chromium.org, Adam Rice

Hi all,


(If you do not work with readable byte streams, you can ignore this.)


We have recently landed the implementation of teeing support for readable byte streams in Blink based on the corresponding spec changes to the Streams API standard. This improves standards compliance.

Based on these changes, teeing a byte stream will now result in creating two readable byte streams, instead of two default readable streams. The implementation also now clones the chunks, instead of using the same ArrayBufferView, when teeing. This means that if you compare the output of the two streams, it’s possible to observe that the objects differ with the new behavior, which is demonstrated by the following script:


const byteStream = new ReadableStream({ type: ‘bytes’ });

const [branch1, branch2] = byteStream.tee();

const { value: value1 } = branch1.getReader().read();

const { value: value2 } = branch2.getReader().read();

if (value1 === value2) { 

  console.log('old behavior');

} else {

  console.log('new behavior');

}

Cheers,
Nidhi Jaju

Reply all
Reply to author
Forward
0 new messages