std@0.116.0/streams

Deno standard library
GitHub Stars
2192
Go to latest
import * as mod from "https://deno.land/std@0.116.0/streams/mod.ts";

Classes

DelimiterStream

Transform a stream into a stream where each chunk is divided by a given delimiter.

LineStream

Transform a stream into a stream where each chunk is divided by a newline, be it \n or \r\n.

Functions

copy

Copies from src to dst until either EOF (null) is read from src or an error occurs. It resolves to the number of bytes copied or rejects with the first error encountered while copying.

iterateReader

Turns a Reader, r, into an async iterator.

iterateReaderSync

Turns a ReaderSync, r, into an iterator.

mergeReadableStreams

Merge multiple streams into a single one, not taking order into account. If a stream ends before other ones, the other will continue adding data, and the finished one will not add any more data.

readableStreamFromIterable

Create a ReadableStream from any kind of iterable.

readableStreamFromReader

Create a ReadableStream<Uint8Array> from from a Deno.Reader.

readAll

Read Reader r until EOF (null) and resolve to the content as Uint8Array`.

readAllSync

Synchronously reads Reader r until EOF (null) and returns the content as Uint8Array.

readerFromIterable

Create a Deno.Reader from an iterable of Uint8Arrays.

readerFromStreamReader

Create a Reader from a ReadableStreamDefaultReader.

writableStreamFromWriter

Create a WritableStream from a Writer.

writeAll

Write all the content of the array buffer (arr) to the writer (w).

writeAllSync

Synchronously write all the content of the array buffer (arr) to the writer (w).

writerFromStreamWriter

Create a Writer from a WritableStreamDefaultWriter.

zipReadableStreams

Merge multiple streams into a single one, taking order into account, and each stream will wait for a chunk to enqueue before the next stream can append another chunk. If a stream ends before other ones, the other will continue adding data in order, and the finished one will not add any more data.

std/streams

Conversion

readerFromStreamReader

Creates a Reader from a ReadableStreamDefaultReader.

import {
  copy,
  readerFromStreamReader,
} from "https://deno.land/std@0.116.0/streams/mod.ts";
const res = await fetch("https://deno.land");
const file = await Deno.open("./deno.land.html", { create: true, write: true });

const reader = readerFromStreamReader(res.body!.getReader());
await copy(reader, file);
file.close();

writerFromStreamWriter

Creates a Writer from a WritableStreamDefaultWriter.

import {
  copy,
  writerFromStreamWriter,
} from "https://deno.land/std@0.116.0/streams/mod.ts";
const file = await Deno.open("./deno.land.html", { read: true });

const writableStream = new WritableStream({
  write(chunk): void {
    console.log(chunk);
  },
});
const writer = writerFromStreamWriter(writableStream.getWriter());
await copy(file, writer);
file.close();