std@0.144.0/streams

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

Utilities for working with the Streams API. Includes buffering and conversion.

Classes

Buffer

A variable-sized buffer of bytes with read() and write() methods.

DelimiterStream

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

LimitedBytesTransformStream

A TransformStream that will only read & enqueue size amount of bytes. This operation is chunk based and not BYOB based, and as such will read more than needed.

LimitedTransformStream

A TransformStream that will only read & enqueue size amount of chunks.

LineStream 👎 deprecated
TextDelimiterStream

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

TextLineStream

Transform a stream into a stream where each chunk is divided by a newline, be it \n or \r\n. \r can be enabled via the allowCR option.

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.

earlyZipReadableStreams

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 others will be cancelled.

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.

toTransformStream

Convert the generator function into a TransformStream.

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 others 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.144.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.144.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();