Skip to content
Advertisement

How to pipe two ReadableStreams into one WritableStream in Javascript?

I have two ReadableStreams, and I want to pipe them into one WritableStream, where any data that comes through the ReadableStreams goes directly into the WritableStream right then.

I can do the opposite, by using ReadableStream.prototype.tee() to split one ReadableStream into two, but I do not know how to combine two into one.

JavaScript
JavaScript

Advertisement

Answer

Manually, by racing the most recent read from each reader to produce the overall read and initiating those reads as necessary:

JavaScript

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement