CKTIS / JavaScript
ReadableStream — reading data in chunks
ReadableStream provides chunked data consumption. A reader retrieves chunks asynchronously without requiring the entire input to be collected first.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new ReadableStream(underlyingSource?, strategy?)ReadableStream belongs to the Streams Standard, not ECMAScript. Default streams carry arbitrary JavaScript values; type: "bytes" enables BYOB reads into consumer-supplied buffers.
Sources use enqueue() to add chunks. close() lets the queue drain; errors reject reads. read() returns a promise for { value, done }.
getReader() locks the stream to one reader. releaseLock() unlocks without canceling the source. With an active reader, cancel through reader.cancel(); cancellation discards the queue.
pull() supports demand-driven production; unconditional enqueue() can grow the queue despite backpressure. Check target-environment support; Node 24 does not establish browser support.
Examples
async function main() {
const stream = new ReadableStream({
start(controller) {
controller.enqueue("A");
controller.enqueue("B");
controller.close();
}
});
const reader = stream.getReader();
let text = "";
try {
while (true) {
const { value, done } = await reader.read();
if (done) break;
text += value;
}
} finally {
reader.releaseLock();
}
console.log(text);
}
main().catch(console.error);Result
AB
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.