Skip to content

transformStream

transformStream<T, U>(stream, transform): ReadableStream<U>

Defined in: stream-utils.ts:246

Transform a ReadableStream by applying a function to each chunk.

This utility creates a new ReadableStream that applies a transformation function to each chunk from the source stream. The transform function can be synchronous or asynchronous, allowing for complex processing pipelines. Useful for modifying stream data types or content on-the-fly.

T

U

ReadableStream<T>

Source ReadableStream to transform

(chunk) => U | Promise<U>

Function to apply to each chunk (sync or async)

ReadableStream<U>

New ReadableStream emitting transformed chunks

const textStream = fetchStream(); // ReadableStream<Uint8Array>
const uppercaseStream = transformStream(textStream, (chunk) => {
const text = new TextDecoder().decode(chunk);
return new TextEncoder().encode(text.toUpperCase());
});