Skip to main content
Module

x/jsonlines/mod.ts>transformStreamFromGeneratorFunction

Web stream based jsonlines decoder/encoder
Latest
function transformStreamFromGeneratorFunction
import { transformStreamFromGeneratorFunction } from "https://deno.land/x/jsonlines@v1.2.2/mod.ts";

Convert the generator function into a TransformStream.

import { readableStreamFromIterable } from "https://deno.land/std@0.185.0/streams/mod.ts";
import { transformStreamFromGeneratorFunction } from "https://deno.land/x/jsonlines@v1.2.1/mod.ts";

const reader = readableStreamFromIterable([0, 1, 2])
  .pipeThrough(transformStreamFromGeneratorFunction(async function* (src) {
    for await (const chunk of src) {
      yield chunk * 100;
    }
  }));

for await (const chunk of reader) {
  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.