Skip to main content

@std/streams@0.215.0

latest
Works with
It is unknown whether this package works with Node.js, Deno, Browsers, Cloudflare Workers, Bun
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
default

Utilities for working with the Streams API.

Classes

c
Buffer(ab?: ArrayBufferLike | ArrayLike<number>)

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

  • bytes(options?): Uint8Array

    Returns a slice holding the unread portion of the buffer.

  • capacity(): number

    The read only capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.

  • empty(): boolean

    Returns whether the unread portion of the buffer is empty.

  • grow(n: number): void

    Grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After .grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, .grow() will throw. If the buffer can't grow it will throw an error.

  • length(): number

    A read only number of bytes of the unread portion of the buffer.

  • readable(): ReadableStream<Uint8Array>

    Getter returning the instance's ReadableStream.

  • reset(): void

    Resets to an empty buffer.

  • truncate(n: number): void

    Discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It throws if n is negative or greater than the length of the buffer.

  • writable(): WritableStream<Uint8Array>

    Getter returning the instance's WritableStream.

c
ByteSliceStream(
start?,
end?: number
)

A transform stream that only transforms from the zero-indexed start and end bytes (both inclusive).

c
DelimiterStream(
delimiter: Uint8Array,
options?: DelimiterStreamOptions
)

Divide a stream into chunks delimited by a given byte sequence.

c
LimitedBytesTransformStream(
size: number,
options?: { error?: boolean; }
)

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.

c
LimitedTransformStream<T>(
size: number,
options?: { error?: boolean; }
)

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

c
TextDelimiterStream(
delimiter: string,
options?: DelimiterStreamOptions
)

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

c
TextLineStream(options?: TextLineStreamOptions)

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

f
earlyZipReadableStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>

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.

f
mergeReadableStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>

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.

f
toArrayBuffer(readableStream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>

Converts a ReadableStream of Uint8Arrays to an ArrayBuffer. Works the same asResponse.arrayBuffer.

f
toBlob(stream: ReadableStream<Uint8Array>): Promise<Blob>

Converts a ReadableStream of Uint8Arrays to a Blob. Works the same as Response.blob.

f
toJson(readableStream: ReadableStream): Promise<unknown>

Converts a JSON-formatted ReadableSteam of strings or Uint8Arrays to an object. Works the same as Response.json.

f
toText(readableStream: ReadableStream): Promise<string>

Converts a ReadableSteam of strings or Uint8Arrays to a single string. Works the same as Response.text.

f
toTransformStream<I, O>(
transformer: (src: ReadableStream<I>) => Iterable<O> | AsyncIterable<O>,
writableStrategy?: QueuingStrategy<I>,
readableStrategy?: QueuingStrategy<O>
): TransformStream<I, O>

Convert the generator function into a TransformStream.

f
zipReadableStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>

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.

f
iterateReader(
r: Reader,
options?: { bufSize?: number; }
): AsyncIterableIterator<Uint8Array>

Turns a Reader, r, into an async iterator.

f
iterateReaderSync(
r: ReaderSync,
options?: { bufSize?: number; }
): IterableIterator<Uint8Array>

Turns a ReaderSync, r, into an iterator.

f
readableStreamFromReader(
reader: Reader | (Reader & Closer),
options?: ReadableStreamFromReaderOptions
): ReadableStream<Uint8Array>

Create a ReadableStream of Uint8Arrays from a Reader.

f
readerFromIterable(iterable: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): Reader

Create a Reader from an iterable of Uint8Arrays.

f
readerFromStreamReader(streamReader: ReadableStreamDefaultReader<Uint8Array>): Reader

Create a Reader from a ReadableStreamDefaultReader.

f
writableStreamFromWriter(
writer: Writer,
options?: WritableStreamFromWriterOptions
): WritableStream<Uint8Array>

Create a WritableStream from a Writer.

f
writerFromStreamWriter(streamWriter: WritableStreamDefaultWriter<Uint8Array>): Writer

Create a Writer from a WritableStreamDefaultWriter.

Interfaces

I

Options for DelimiterStream.

  • disposition: DelimiterDisposition

    Disposition of the delimiter.

I

Options for TextLineStream.

  • allowCR: boolean

    Allow splitting by \r.

I

Options for readableStreamFromReader.

  • autoClose: boolean

    If the reader is also a Closer, automatically close the reader when EOF is encountered, or a read error occurs.

  • chunkSize: number

    The size of chunks to allocate to read, the default is ~16KiB, which is the maximum size that Deno operations can currently support.

  • strategy: { highWaterMark?: number | undefined; size?: undefined; }

    The queuing strategy to create the ReadableStream with.

I

Options for writableStreamFromWriter.

  • autoClose: boolean

    If the writer is also a Closer, automatically close the writer when the stream is closed, aborted, or a write error occurs.

Type Aliases

T
DelimiterDisposition = "suffix" | "prefix" | "discard"

Disposition of the delimiter for DelimiterStreamOptions.

buffer

Classes

c
Buffer(ab?: ArrayBufferLike | ArrayLike<number>)

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

  • bytes(options?): Uint8Array

    Returns a slice holding the unread portion of the buffer.

  • capacity(): number

    The read only capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.

  • empty(): boolean

    Returns whether the unread portion of the buffer is empty.

  • grow(n: number): void

    Grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After .grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, .grow() will throw. If the buffer can't grow it will throw an error.

  • length(): number

    A read only number of bytes of the unread portion of the buffer.

  • readable(): ReadableStream<Uint8Array>

    Getter returning the instance's ReadableStream.

  • reset(): void

    Resets to an empty buffer.

  • truncate(n: number): void

    Discards all but the first n unread bytes from the buffer but continues to use the same allocated storage. It throws if n is negative or greater than the length of the buffer.

  • writable(): WritableStream<Uint8Array>

    Getter returning the instance's WritableStream.

byte_slice_stream

Classes

c
ByteSliceStream(
start?,
end?: number
)

A transform stream that only transforms from the zero-indexed start and end bytes (both inclusive).

delimiter_stream

Classes

c
DelimiterStream(
delimiter: Uint8Array,
options?: DelimiterStreamOptions
)

Divide a stream into chunks delimited by a given byte sequence.

Interfaces

I

Options for DelimiterStream.

  • disposition: DelimiterDisposition

    Disposition of the delimiter.

Type Aliases

T
DelimiterDisposition = "suffix" | "prefix" | "discard"

Disposition of the delimiter for DelimiterStreamOptions.

early_zip_readable_streams

Functions

f
earlyZipReadableStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>

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.

iterate_reader

Functions

f
iterateReader(
r: Reader,
options?: { bufSize?: number; }
): AsyncIterableIterator<Uint8Array>

Turns a Reader, r, into an async iterator.

f
iterateReaderSync(
r: ReaderSync,
options?: { bufSize?: number; }
): IterableIterator<Uint8Array>

Turns a ReaderSync, r, into an iterator.

limited_bytes_transform_stream

Classes

c
LimitedBytesTransformStream(
size: number,
options?: { error?: boolean; }
)

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.

limited_transform_stream

Classes

c
LimitedTransformStream<T>(
size: number,
options?: { error?: boolean; }
)

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

merge_readable_streams

Functions

f
mergeReadableStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>

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.

readable_stream_from_reader

Functions

f
readableStreamFromReader(
reader: Reader | (Reader & Closer),
options?: ReadableStreamFromReaderOptions
): ReadableStream<Uint8Array>

Create a ReadableStream of Uint8Arrays from a Reader.

Interfaces

I

Options for readableStreamFromReader.

  • autoClose: boolean

    If the reader is also a Closer, automatically close the reader when EOF is encountered, or a read error occurs.

  • chunkSize: number

    The size of chunks to allocate to read, the default is ~16KiB, which is the maximum size that Deno operations can currently support.

  • strategy: { highWaterMark?: number | undefined; size?: undefined; }

    The queuing strategy to create the ReadableStream with.

reader_from_iterable

Functions

f
readerFromIterable(iterable: Iterable<Uint8Array> | AsyncIterable<Uint8Array>): Reader

Create a Reader from an iterable of Uint8Arrays.

reader_from_stream_reader

Functions

f
readerFromStreamReader(streamReader: ReadableStreamDefaultReader<Uint8Array>): Reader

Create a Reader from a ReadableStreamDefaultReader.

text_delimiter_stream

Classes

c
TextDelimiterStream(
delimiter: string,
options?: DelimiterStreamOptions
)

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

text_line_stream

Classes

c
TextLineStream(options?: TextLineStreamOptions)

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.

Interfaces

I

Options for TextLineStream.

  • allowCR: boolean

    Allow splitting by \r.

to_array_buffer

Functions

f
toArrayBuffer(readableStream: ReadableStream<Uint8Array>): Promise<ArrayBuffer>

Converts a ReadableStream of Uint8Arrays to an ArrayBuffer. Works the same asResponse.arrayBuffer.

to_blob

Functions

f
toBlob(stream: ReadableStream<Uint8Array>): Promise<Blob>

Converts a ReadableStream of Uint8Arrays to a Blob. Works the same as Response.blob.

to_json

Functions

f
toJson(readableStream: ReadableStream): Promise<unknown>

Converts a JSON-formatted ReadableSteam of strings or Uint8Arrays to an object. Works the same as Response.json.

to_text

Functions

f
toText(readableStream: ReadableStream): Promise<string>

Converts a ReadableSteam of strings or Uint8Arrays to a single string. Works the same as Response.text.

to_transform_stream

Functions

f
toTransformStream<I, O>(
transformer: (src: ReadableStream<I>) => Iterable<O> | AsyncIterable<O>,
writableStrategy?: QueuingStrategy<I>,
readableStrategy?: QueuingStrategy<O>
): TransformStream<I, O>

Convert the generator function into a TransformStream.

writable_stream_from_writer

Functions

f
writableStreamFromWriter(
writer: Writer,
options?: WritableStreamFromWriterOptions
): WritableStream<Uint8Array>

Create a WritableStream from a Writer.

Interfaces

I

Options for writableStreamFromWriter.

  • autoClose: boolean

    If the writer is also a Closer, automatically close the writer when the stream is closed, aborted, or a write error occurs.

writer_from_stream_writer

Functions

f
writerFromStreamWriter(streamWriter: WritableStreamDefaultWriter<Uint8Array>): Writer

Create a Writer from a WritableStreamDefaultWriter.

zip_readable_streams

Functions

f
zipReadableStreams<T>(...streams: ReadableStream<T>[]): ReadableStream<T>

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.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/streams

Import symbol

import * as streams from "@std/streams";
or

Import directly with a jsr specifier

import * as streams from "jsr:@std/streams";