Contact emails
ri...@chromium.org, tyos...@chromium.org (implementation); dom...@chromium.org (spec)
Spec
The Streams Standard, pipeTo() section: https://streams.spec.whatwg.org/#rs-pipe-to.
pipeThrough() section: https://streams.spec.whatwg.org/#rs-pipe-through.
Summary
ReadableStream's pipeTo() is the standard way to compose Streams. It reads data from the underlying source and writes it to a WritableStream while respecting backpressure. It is designed to permit optimisations when connecting platform streams by direct access to the underlying data sources.
pipeThrough() is a simple wrapper around pipeTo() that provides elegant syntax for chaining multiple streams. Example:
httpResponseBody
.pipeThrough(transformation)
.pipeTo(destination);
Here transformation is a transform stream that converts data to another format.
Motivation
The Streams API provides a standard API and terminology for dealing with streaming data in the browser, replacing the ad hoc designs and implementations that have been used up until now. The most fundamental operation on streams is connecting them via pipes.
The pipeTo() method was not included in the initial implementation of ReadableStream in Blink as it was not required by the Fetch API. However, now that WritableStream is implemented it is a good time to plug this implementation gap.
The semantics of the pipeTo() method can be implemented in user JavaScript, but as a fundamental primitive it is better for it to be universally available with standard semantics. In addition, as the implementation is not exposed to user JavaScript, it is not restricted to using public APIs and additional optimisation can be applied.
pipeThrough() is syntactic sugar which provides an easy-to-read syntax for transforming a pipe of data. Although it is designed to work well with transform streams, it will work with any transformation that exposed a { writable, readable } pair.
See the standard for more examples.
Interoperability Risk
Low.
Gecko and WebKit representatives have been actively involved in discussion of the spec. We have already developed a large suite of web platform tests with high coverage against the reference implementation. We intend to upstream these tests to the w3c web-platform-tests repository soon, as been done for readable streams; for now they are being iterated on inside the spec repo. WebKit developers have also been participating in authoring web-platform tests.
ReadableStream has already paved the way with excellent interoperability. It is currently shipping in Edge, WebKit, and Blink with compatible semantics, with Gecko following close behind.
Compatibility Risk
Low.
The pipeTo() standard has been finalised.
The pending spec issues can be found at in the spec repository. The remaining discussions concern future extensions, notably support for cancelable promises.
Ongoing technical constraints
None.
Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?
Yes.
OWP launch tracking bug
https://bugs.chromium.org/p/chromium/issues/detail?id=668951
Link to entry on the feature dashboard
https://www.chromestatus.com/feature/6067348976959488
Requesting approval to ship?
No.