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
Usefor 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:
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 aResponse or Request to create a streaming response without constructing a ReadableStream manually:
Symbol.asyncIterator:
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:
.pipeThrough() to pass a stream through a TransformStream:
Streaming HTTP responses
Return aReadableStream 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)
Usestream: true to flush the sink in chunks rather than collecting everything until .end():
.flush() returns the buffered data and resets the internal buffer.
Pre-allocating the buffer
SethighWaterMark 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 implementsnode:stream. You can use Readable, Writable, Duplex, and Transform exactly as you would in Node.js: