Re: [streams] Support reading bytes into buffers allocated by user code on platforms where only async read is available (#253)

Suddenly all the thoughts are coming to my head at the last minute when it's time to leave for the day.

We could have getReader() on ReadableByteStream behave just like on ReadableStream. It returns a normal reader with no argument to read(). And in doing so it starts an "auto-flowing" mode that can e.g. queue up a few chunks ahead of time, if desired.

But then it also has a getBYOBReader() (or something) that has a read(view) method.

Then, inside RBS.prototype.pipeTo, the code looks at the destination. Is it a WritableByteStream? If so, use this.getBYOBReader(), and set up a buffer pool and use read(view). Otherwise, use this.getReader() to get the same generic behavior.

Ever since I realized your separate byte-sources-vs.-streams separation could be reframed as streams-vs.-readers I like it more and more, and start to appreciate the beauty of it. Sorry it took me so long!

---
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/253#issuecomment-77495270

Received on Friday, 6 March 2015 02:23:26 UTC