Skip to content

Streams

How Elide supports ReadableStream, WritableStream and TransformStream per the Streams Standard, including byte streams, BYOB readers and from().

Read offlineelide help api-whatwg-streams

On this page

ReadableStream, WritableStream, TransformStream, their readers, writers, and controllers, CountQueuingStrategy, and ByteLengthQueuingStrategy are globals. They follow the Streams Standard, including byte streams, BYOB readers, and ReadableStream.from().

Example

js
// webstreams.mjs
const numbers = ReadableStream.from([1, 2, 3, 4]);
const doubled = numbers.pipeThrough(
  new TransformStream({
    transform(n, controller) {
      controller.enqueue(n * 2);
    },
  }),
);

const seen = [];
await doubled.pipeTo(
  new WritableStream({
    write(n) {
      seen.push(n);
    },
  }),
);
console.log(seen.join(" "));

const text = await new Response(ReadableStream.from(["he", "llo"]).pipeThrough(new TextEncoderStream())).text();
console.log(text);
utf-8 · js · Lines: 22

elide run webstreams.mjs prints:

text
2 4 6 8
hello
utf-8 · text · Lines: 2

Differences from browsers

  • A stream cannot be transferred to a worker: naming one in a postMessage transfer list throws DataCloneError.

For byte transforms, see Compression Streams.

Reference

Status: Full · Not measured · since 1.1.0

Exports

Export Kind Status Notes
ReadableStream class Full locked, cancel(), getReader(), pipeThrough(), pipeTo(), tee()
ReadableStreamDefaultReader class Full closed, read(), releaseLock(), cancel()
ReadableStreamDefaultController class Full desiredSize, close(), enqueue(), error()
ReadableStreamBYOBReader class Full closed, read(), releaseLock(), cancel()
ReadableByteStreamController class Full byobRequest, desiredSize, close(), enqueue(), error()
ReadableStreamBYOBRequest class Full view, respond(), respondWithNewView()
WritableStream class Full locked, abort(), close(), getWriter()
WritableStreamDefaultWriter class Full closed, desiredSize, ready, abort(), close(), releaseLock(), write()
WritableStreamDefaultController class Full signal, error()
TransformStream class Full readable, writable
TransformStreamDefaultController class Full desiredSize, enqueue(), error(), terminate()
CountQueuingStrategy class Full highWaterMark, size
ByteLengthQueuingStrategy class Full highWaterMark, size

Was this page helpful?