std/streams/conversion.ts

Deno standard library
Go to Latest
function toTransformStream
import { toTransformStream } from "https://deno.land/std@0.147.0/streams/conversion.ts?s=toTransformStream";

Convert the generator function into a TransformStream.

import { readableStreamFromIterable, toTransformStream } from "./conversion.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>[src]

A function to transform.

optional
writableStrategy: QueuingStrategy<I>
[src]

An object that optionally defines a queuing strategy for the stream.

optional
readableStrategy: QueuingStrategy<O>
[src]

An object that optionally defines a queuing strategy for the stream.

Returns

TransformStream<I, O>[src]