Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/proc/src/deps/streams.ts>toTransformStream

A high-level way to run child processes that is easy, flexible, powerful, and prevents resource leaks.
Go to Latest
function toTransformStream
import { toTransformStream } from "https://deno.land/x/proc@0.20.7/src/deps/streams.ts";

Convert the generator function into a TransformStream.

import { readableStreamFromIterable } from "https://deno.land/std@0.224.0/streams/readable_stream_from_iterable.ts";
import { toTransformStream } from "https://deno.land/std@0.224.0/streams/to_transform_stream.ts";

const readable = readableStreamFromIterable([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

Parameters

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.