new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Cloudflare Workers · Runtime APIs · all subjects

streams api

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

ReadableStream locked property

ReadableStream has a boolean property called locked that indicates if the readable stream is locked to a reader.

ReadableStream pipeTo method

pipeTo(destinationWritableStream, optionsPipeToOptions) returns Promise<void>. It pipes the readable stream to a given writable stream destination and returns a promise that is fulfilled when the write operation succeeds or rejects if the operation fails. Options accepts preventClose (bool) and preventAbort (bool). When preventClose is true, closure of the source ReadableStream will not cause the destination WritableStream to be closed. When preventAbort is true, errors in the source ReadableStream will no longer abort the destination WritableStream; pipeTo will return a rejected promise with the error from the source or any error that occurred while aborting the destination.

ReadableStream pipeThrough method

pipeThrough(transformStream, optionsPipeToOptions) returns ReadableStream. It pipes the readable stream to the writable side of a given TransformStream and returns the transform's readable side, so that calls can be chained. Options accepts the same values as pipeTo().

ReadableStream getReader method

getReader(optionsObject) returns ReadableStreamDefaultReader. It gets an instance of ReadableStreamDefaultReader and locks the ReadableStream to that reader instance. The method accepts an object argument indicating options. The only supported option is mode, which can be set to 'byob' to create a ReadableStreamBYOBReader.

ReadableStream cancel method

cancel(reasonstringoptional) returns Promise<void>. It cancels the stream. The reason parameter is an optional human-readable string indicating the reason for cancellation. Reason will be passed to the underlying source's cancel algorithm. Any data not yet read is lost.

ReadableStream tee method

tee() returns [ReadableStream, ReadableStream]. It locks the stream and returns an array of two new ReadableStream instances, 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.

ReadableStream values method

values(optionsObject) returns AsyncIterableIterator. It returns an async iterator that reads and consumes the chunks of the stream. The method accepts an object argument indicating options. The only supported option is preventCancel, which when true prevents the stream from being canceled when the iterator exits early (for example, from a break statement). A ReadableStream is also async iterable directly, allowing usage like: for await (const chunk of readable) { console.log(chunk); }

ReadableStream.from static method

ReadableStream.from(asyncIterable) returns ReadableStream. It creates a new ReadableStream whose chunks are the values yielded by asyncIterable, which may be any iterable or async iterable, including an async generator.

ReadableStream.from example with async generator

const stream = ReadableStream.from( (async function* () { yield 'hello '; yield 'world'; })() );

ReadableStream getReader example with BYOB mode

let reader = readable.getReader({ mode: 'byob' });

ReadableStream async iteration example

for await (const chunk of readable) { console.log(chunk); }

Give your agent this brain