Skip to content

Idiomatic Way to Explicitly Tell an Underlying Transform Stream to Flush to the Sink #960

Open
@sebmarkbage

Description

@sebmarkbage

Sometimes transform 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 sending 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 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 awkward 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions