Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function readerFromIterable
Deprecated
Deprecated

(will be removed after 1.0.0) Use ReadableStream.from instead.

import { readerFromIterable } from "https://deno.land/std@0.220.0/streams/mod.ts";

Create a Reader from an iterable of Uint8Arrays.

import { readerFromIterable } from "https://deno.land/std@0.220.0/streams/reader_from_iterable.ts";
import { copy } from "https://deno.land/std@0.220.0/io/copy.ts";

const file = await Deno.open("build.txt", { write: true });
const reader = readerFromIterable((async function* () {
  while (true) {
    await new Promise((r) => setTimeout(r, 1000));
    const message = `data: ${JSON.stringify(Deno.build)}\n\n`;
    yield new TextEncoder().encode(message);
  }
})());
await copy(reader, file);

Parameters

iterable: Iterable<Uint8Array> | AsyncIterable<Uint8Array>