Re: [streams] How will ReadableByteStream work with seekable resources? (#253)

> Hmm, yeah, readInto() makes less sense here.

Yeah. Streams with fread style underlying source would be queue-backed stream (though it's likely to be a single element queue) (see https://github.com/whatwg/streams/pull/275#issuecomment-73470112). So, `readInto()` is not useful but introduces an extra copy. Ben's https://github.com/whatwg/streams/issues/253#issuecomment-73938444 should just work.

----

> One advantage of setAllocator over feedArrayBuffer is

I agree that the new user doesn't need to do the feeding, but the new user needs to:

- understand the internal mechanism of AllocaterControlledReadableStream,
- know what kind of allocator the previous user set to the stream,
- and be aware of the timing the previously used ArrayBuffers will be reused.

These were not required for normal ReadableStream user. So, I think streams to pass to someone else should have an allocator that doesn't reuse ArrayBuffers.

For use cases in which the consumer code wants to adjust the size to pull (pass to `fread()`):

- In such cases, `.feedArrayBuffer()` is simpler than updating some value in the allocator closure. Another approach is calling `setAllocator()` again and again for updating allocator. This might be as simple as `.feedArrayBuffer()`, but the user should be aware of when the internal mechanism invokes `fread()`.
- `.feedArrayBuffer()` approach can tell the stream to stop pulling (calling fread()) simply by not calling `.feedArrayBuffer()` while `setAllocator()` needs to return a pending Promise as Ben said like the new `underlyingSource.pull()`.

So, I suggest that we encapsulate `fread()` style underlying byte source by say, ManualBufferFeedReadableStream that has `.feedArrayBuffer()` but also has some switch to make it "auto-pull" or even `.setAllocator()` method to accept custom ArrayBuffer allocator so that it can be passed to ReadableStream consumers. Or, we could also introduce kind of "joint" (like transform-stream concept) that encapsulates the `fread()` style ReadableStream, calls `.feedArrayBuffer` appropriately and exports ReadableStream interface.

Hmm, but now I wonder if this is something we should define in the Streams standard or not. Maybe we should just include some advice how to encapsulate blocking I/Os with the ReadableStream interface?

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

Received on Thursday, 12 February 2015 10:54:07 UTC