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.
Type Parameters
Section titled “Type Parameters”T
U
Parameters
Section titled “Parameters”stream
Section titled “stream”ReadableStream<T>
Source ReadableStream to transform
transform
Section titled “transform”(chunk) => U | Promise<U>
Function to apply to each chunk (sync or async)
Returns
Section titled “Returns”ReadableStream<U>
New ReadableStream emitting transformed chunks
Example
Section titled “Example”const textStream = fetchStream(); // ReadableStream<Uint8Array>const uppercaseStream = transformStream(textStream, (chunk) => { const text = new TextDecoder().decode(chunk); return new TextEncoder().encode(text.toUpperCase());});