Skip to main content
Streams let you process data incrementally without loading it all into memory at once. Bun implements the Web Streams API (ReadableStream, WritableStream, TransformStream) and the Node.js node:stream module.
Bun also implements node:stream, including Readable, Writable, Duplex, and Transform. For complete Node.js stream docs, refer to the Node.js documentation.

ReadableStream

Creating a ReadableStream

Consuming a ReadableStream

Use for await...of to consume a stream chunk by chunk:

Direct ReadableStream (Bun-specific)

Bun implements an optimized "direct" stream type that avoids copying chunks into an internal queue. Use it when you want to write directly to the stream’s underlying sink:
The standard enqueue() copies data into a queue. write() on a direct stream skips the queue entirely, which reduces memory pressure and latency for large or frequent writes.

Async generator streams

Pass an async generator function as the body of a Response or Request to create a streaming response without constructing a ReadableStream manually:
You can also use Symbol.asyncIterator:
For more control, yield returns the direct stream controller:

WritableStream


TransformStream

TransformStream sits between a readable and writable stream, transforming data as it passes through:

Piping streams

Use .pipeTo() to pipe a ReadableStream directly into a WritableStream:
Use .pipeThrough() to pass a stream through a TransformStream:

Streaming HTTP responses

Return a ReadableStream as a Response body to stream data to the client:

Bun.ArrayBufferSink

Bun.ArrayBufferSink is a fast, incremental writer for collecting stream chunks into an ArrayBuffer (or Uint8Array).

Basic usage

Get a Uint8Array instead of ArrayBuffer

Stream mode (flush repeatedly)

Use stream: true to flush the sink in chunks rather than collecting everything until .end():
Each call to .flush() returns the buffered data and resets the internal buffer.

Pre-allocating the buffer

Set highWaterMark to pre-allocate an internal buffer of a known size, which improves performance when writing many small chunks:

Converting between formats

ReadableStream to other formats

Bun provides optimized helper functions that avoid the overhead of wrapping in Response:

Other types to ReadableStream

Split a stream with .tee()


Node.js streams compatibility

Bun fully implements node:stream. You can use Readable, Writable, Duplex, and Transform exactly as you would in Node.js:

Converting between Web streams and Node.js streams


ArrayBufferSink API reference