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)

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

  • disposition: DelimiterDisposition

    Disposition of the delimiter.

  • allowCR: boolean

    Allow splitting by \r.

  • 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.

  • 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.

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.