[whatwg/streams] Idiomatic Way to Explicitly Tell an Underlying Transform Stream to Flush to the Sink (#960)

Sometimes tranform streams keep some internal state and keeps a buffer window. It then waits to flush that buffer to the readable stream until the buffer window is full. Examples of this include compression and encryption libraries.

This can however cause problems when the source stream has to wait a long time for the next piece of data but the receiver can do something useful with it. For example, generating a HTML document that can be displayed in partial pieces, or setting a list of chat messages while waiting for the next message. In that case, the source knows that now is a good time to flush to the underlying sink even if that causes inefficient use of the buffer window.

In Node.js's [Zlib module](https://nodejs.org/api/zlib.html#zlib_flushing) that is solved by exposing an explicit `flush()` method on the Writable. I believe .NET has a similar convention for all Streams.

I haven't seen an idiomatic way to solve this with Streams.

This gets particularly akward with Service Workers because there is no `WritableStream` for Responses. So there isn't really anything to call `flush` on. So if the idea is to stick with `ReadableStream` being the only way, then this use case would need to be modeled by having the `ReadableStream` communicate this flush signal intent somehow.



-- 
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/960

Received on Tuesday, 6 November 2018 19:02:42 UTC