Web Streams

ReadableStream.getReader()

Acquires exclusive access through a reader. Release the lock after the read sequence, including failure paths. Tested on Node.js 22.16.0. Example output (one line per entry): ["true book", "false"].

Formal Syntax & Structure

nodejs syntaxnodejs
stream.getReader([options])

Parameters & Attributes

NameTypeDescription
optionsobjectReader mode.

Return Value

ReadableStreamDefaultReader | ReadableStreamBYOBReader

Reader for this stream.

Working Example

Example Snippetnodejs
const s = new ReadableStream({ start(c) { c.enqueue('book'); c.close(); } });const r = s.getReader();try {    console.log(s.locked, (await r.read()).value);}finally {    r.releaseLock();}console.log(s.locked);
Node.js Reference