ReadableStream
Last updated Sep 5, 2026
Background
A ReadableStream is returned by the readable property inside TransformStream.
Properties
lockedboolean- A Boolean value that indicates if the readable stream is locked to a reader.
Methods
pipeTo(destinationWritableStream, optionsPipeToOptions): Promise\<void>- Pipes the readable stream to a given writable stream
destinationand returns a promise that is fulfilled when thewriteoperation succeeds or rejects it if the operation fails. pipeThrough(transformStream, optionsPipeToOptions): ReadableStream- Pipes the readable stream to the writable side of a given
TransformStreamand returns the transform's readable side, so that calls can be chained.optionsaccepts the same values aspipeTo(). getReader(optionsObject): ReadableStreamDefaultReader- Gets an instance of
ReadableStreamDefaultReaderand locks theReadableStreamto that reader instance. This method accepts an object argument indicating options. The only supported option ismode, which can be set tobyobto create aReadableStreamBYOBReader, as shown here:
let reader = readable.getReader({ mode: 'byob' });
cancel(reasonstringoptional): Promise\<void>- Cancels the stream.
reasonis an optional human-readable string indicating the reason for cancellation.reasonwill be passed to the underlying source’s cancel algorithm. Any data not yet read is lost. tee(): [ReadableStream, ReadableStream]- Locks the stream and returns an array of two new
ReadableStreaminstances, each of which reads the same data as the original stream. Backpressure to the underlying source follows the branch with the most unread data, which avoids unbounded buffering when one branch reads more slowly than the other, as long as the underlying source responds to backpressure. Refer to workerd's streams documentation ↗︎ for implementation details. values(optionsObject): AsyncIterableIterator- Returns an async iterator that reads and consumes the chunks of the stream. This method accepts an object argument indicating options. The only supported option is
preventCancel, which, whentrue, prevents the stream from being canceled when the iterator exits early (for example, from abreakstatement). AReadableStreamis also async iterable directly:
for await (const chunk of readable) {
console.log(chunk);
}
for await (const chunk of readable) {
console.log(chunk);
}
PipeToOptions
preventClosebool- When
true, closure of the sourceReadableStreamwill not cause the destinationWritableStreamto be closed. preventAbortbool- When
true, errors in the sourceReadableStreamwill no longer abort the destinationWritableStream.pipeTowill return a rejected promise with the error from the source or any error that occurred while aborting the destination.
Static methods
ReadableStream.from(asyncIterable): ReadableStream- Creates a new
ReadableStreamwhose chunks are the values yielded byasyncIterable, which may be any iterable or async iterable, including an async generator.
const stream = ReadableStream.from(
(async function* () {
yield "hello ";
yield "world";
})(),
);
const stream = ReadableStream.from(
(async function* () {
yield 'hello ';
yield 'world';
})()
);
Related resources
- Streams
- Readable streams in the WHATWG Streams API specification ↗︎
- MDN’s
ReadableStreamdocumentation ↗︎
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/runtime-apis/streams/readablestream/#page","headline":"ReadableStream","description":"Learn about the ReadableStream API for reading streamed data in Cloudflare Workers.","url":"https://developers.cloudflare.com/workers/runtime-apis/streams/readablestream/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/runtime-apis/streams/readablestream/og.png?v=37efd281a5c52d37","dateModified":"2026-09-05","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Use ReadableStreamBYOBReader in Workers to read streamed data into your own buffer. title: ReadableStream BYOBReader image: https://developers.cloudflare.com/workers/runtime-apis/streams/readablestreambyobreader/og.png?v=1764ea6fd8a7f43d
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.
Docs