whatwg / streams

Streams Standard
https://streams.spec.whatwg.org/
Other
1.35k stars 160 forks source link

Allow web authors to tee() with cloned chunks #1156

Open MattiasBuelens opened 3 years ago

MattiasBuelens commented 3 years ago

Currently, ReadableStream.prototype.tee() performs ReadableStreamTee() with cloneForBranch2 always set to false. This means that both branches always see identical chunks (chunk1 === chunk2).

However, in some cases, web authors may want to clone each chunk before it is enqueued to the second branch:

While it is technically possible to implement this in author code, the solution is not pretty:

Therefore, we may want to expose the cloneForBranch2 functionality to web authors. Some suggestions:

Or perhaps we can combine both into one option?

callback ReadableStreamTeeCloneCallback = any (any chunk);

dictionary ReadableStreamTeeOptions {
  clone: (boolean or ReadableStreamTeeCloneCallback);
}

interface ReadableStream {
   sequence<ReadableStream> tee(optional ReadableStreamTeeOptions options);
}

(This issue was split from #1155.)