[streams] What types does ReadableByteStream's reader's read(x) accept and return? (#295)

Per #253 the "bring your own buffer" reader for ReadableByteStream will generally be of the form

```
byobReader.read(view : ArrayBufferView) -> Promise<ArrayBufferView>
```

The reason for an ArrayBufferView for the argument is that it allows authors to supply the (buffer, offset, maxLength) trio all at once. The reason for the ArrayBufferView for the return type is that it gives back (buffer, bytesRead), plus the offset if one was supplied, all at once.

For the input, there are a few possibilities:

- Only allow a specific type: `Uint8Array` and `DataView` are the big candidates
- Allow any array buffer view (including `DataView`), with nominal typing
- Allow any `{ buffer, byteOffset, byteLength }` structure; all array buffer views match this, but it would also allow user-supplied structures if they only have a buffer handy (and we could even default byteOffset = 0 and byteLength = buffer.byteLength).
- Allow any array buffer view (either nominal or structural), but *also* allow array buffers directly.

I think the most lenient option here is probably best: allow structural array buffer views or array buffers directly. Alternately we could just allow structural array buffer views. The only difference is that the former allows `.read(ab)` whereas the latter requires `.read({ buffer: ab })`.

For the return type, I think our choices are: `Uint8Array` or `DataView`. Here `DataView` feels a bit more general---less like "picking favorites". (Why not `Int8Array`? Why not `Uint8ClampedArray`?) But it is also less useful, I think---it doesn't have the nice array methods like `map`/`filter`/etc., or the typed array methods like `set`, and it exposes you to endianness concerns (I think)...

I think `Uint8Array` is best here.

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

Received on Wednesday, 11 March 2015 15:59:20 UTC