Streams WHATWG

Large swathes of the web platform are built on streaming data: that is,
data that is created, processed, and consumed in an incremental fashion,
without ever reading all of it into memory. The Streams Standard provides a
common set of APIs for creating and interfacing with such streaming data,
embodied in readable streams
<https://streams.spec.whatwg.org/#readable-stream>, writable streams
<https://streams.spec.whatwg.org/#writable-stream>, and transform streams
<https://streams.spec.whatwg.org/#transform-stream>.

This standard provides the base stream primitives which other parts of the
web platform can use to expose their streaming data. For example, [FETCH]
<https://streams.spec.whatwg.org/#biblio-fetch> could expose request bodies
as a writable stream, or response bodies as a readable stream. More
generally, the platform is full of streaming abstractions waiting to be
expressed as streams: multimedia streams, file streams, interprocess
communication, and more benefit from being able to process data
incrementally instead of buffering it all into memory and processing it in
one go. By providing the foundation for these streams to be exposed to
developers, the Streams Standard enables use cases like:

   - Video effects: piping a readable video stream through a transform
   stream that applies effects in real time.
   - Decompression: piping a file stream through a transform stream that
   selectively decompresses files from a .tgz archive, turning them into img
   elements as the user scrolls through an image gallery.
   - Image decoding: piping a HTTP response stream through a transform
   stream that decodes bytes into bitmap data, and then through another
   transform that translates bitmaps into PNGs. If installed inside the
   fetch hook of a service worker [SERVICE-WORKERS]
   <https://streams.spec.whatwg.org/#biblio-service-workers>, this would
   allow developers to transparently polyfill new image formats.

The APIs described here provide unifying abstraction for all such streams,
encouraging an ecosystem to grow around these shared and composable
interfaces. At the same time, they have been carefully designed to map
efficiently to low-level I/O concerns, and to encapsulate the trickier
issues (such as backpressure <https://streams.spec.whatwg.org/#backpressure>)
that come along for the ride.


https://streams.spec.whatwg.org/

Received on Wednesday, 5 August 2015 15:04:32 UTC