Re: [whatwg/streams] ReadableStream.prototype.arrayBuffer() (#1019)

> Probably also want to consider an equivalent API where the buffer is already allocated (similar to `encodeInto()`, BYOB).

I like the idea of a method that fills up an entire `ArrayBuffer` (or `ArrayBufferView`). I think it would work better as a reader method, for example `ReadableBYOBReader.readFully(view)` (taken from Java's [`DataInput.readFully()`](https://docs.oracle.com/javase/8/docs/api/java/io/DataInput.html#readFully-byte:A-)). Optionally, we could also add a shorthand method on `ReadableStream`, similar to how `ReadableStream.cancel()` is a shorthand for `ReadableStreamDefaultReader.cancel()`. The `readInto()` function in [this example](https://streams.spec.whatwg.org/#example-manual-read-bytes) seems like a good starting point.

It would be different from `ReadableStream.arrayBuffer()` and/or `ReadableStream.toArray()` though. Those two methods would always read the entire contents of the stream, whereas a `readFully()` method may leave some bytes on the stream if the given buffer is not large enough to fit the entire contents.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1019#issuecomment-565499158

Received on Friday, 13 December 2019 16:06:21 UTC