function toTransformStream
toTransformStream<I, O>(transformer: (src: ReadableStream<I>) => Iterable<O> | AsyncIterable<O>,writableStrategy?: QueuingStrategy<I>,readableStrategy?: QueuingStrategy<O>): TransformStream<I, O>Convert the generator function into a TransformStream.
Examples
Example 1
Example 1
import { toTransformStream } from "@std/streams/to_transform_stream"; const readable = ReadableStream.from([0, 1, 2]) .pipeThrough(toTransformStream(async function* (src) { for await (const chunk of src) { yield chunk * 100; } })); for await (const chunk of readable) { console.log(chunk); } // output: 0, 100, 200
Type Parameters
IOParameters
transformer: (src: ReadableStream<I>) => Iterable<O> | AsyncIterable<O>A function to transform.
optional
writableStrategy: QueuingStrategy<I>An object that optionally defines a queuing strategy for the stream.
optional
readableStrategy: QueuingStrategy<O>An object that optionally defines a queuing strategy for the stream.