Re: [whatwg/streams] ReadableStreamBYOBReader.prototype.readFully(view) (#1143)

It shouldn't be that difficult. Currently #1145 works by adding a *fill* boolean flag to each pull-into descriptor to decide if it should fill up to at least *element size* (for `read(view)`) or up to *byte length* (for `fill(view)`). We can generalize this: replace the flag with a *minimum fill length* property, and let the user configure it directly.

I do like that we can express everything in terms of `fill(view, { minBytes })`:
* `fill(view)` is equivalent to `fill(view, { minBytes: view.byteLength })`
* `read(view)` is equivalent to `fill(view, { minBytes: view.constructor.BYTES_PER_ELEMENT })`

Not 100% sure about the API though, but we can do some bikeshedding. 😁 
* `read(view, { minBytes })`, where `minBytes` defaults to view's element size to match today's behavior. Then we don't really need a dedicated `fill(view)`, but it could still act as a shorthand for `read(view, { minBytes: view.byteLength })` if desired.
* `fill(view, { minBytes })`, where `minBytes` defaults to view's byte length to match the original `fill(view)` proposal. But maybe this makes it too easy to forget about `minBytes`, and you might accidentally end up waiting for the view to be *entirely* filled? 🤷
* `readAtLeast(view, minBytes)`, with no defaults. Less likely to make a mistake, but might be a bit verbose.

-- 
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/1143#issuecomment-942762961

Received on Wednesday, 13 October 2021 22:19:32 UTC