close
Skip to main content

@std/io@0.225.3
Built and signed on GitHub Actions

Works with
This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score94%
Downloads2,185/wk
Published3 months ago (0.225.3)

UNSTABLE: The utilities for advanced I/O operations using Reader and Writer interfaces.

Classes

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

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

  • bytes(options?: { copy: boolean; }): 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.

  • read(p: Uint8Array): Promise<number | null>

    Reads the next p.length bytes from the buffer or until the buffer is drained. Resolves to the number of bytes read. If the buffer has no data to return, resolves to EOF (null).

  • readFrom(r: Reader): Promise<number>

    Reads data from r until EOF (null) and appends it to the buffer, growing the buffer as needed. It resolves to the number of bytes read. If the buffer becomes too large, .readFrom() will reject with an error.

  • readFromSync(r: ReaderSync): number

    Reads data from r until EOF (null) and appends it to the buffer, growing the buffer as needed. It returns the number of bytes read. If the buffer becomes too large, .readFromSync() will throw an error.

  • readSync(p: Uint8Array): number | null

    Reads the next p.length bytes from the buffer or until the buffer is drained. Returns the number of bytes read. If the buffer has no data to return, the return is EOF (null).

  • reset(): void

    Resets the contents

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

  • write(p: Uint8Array): Promise<number>

    Writes the given data to the buffer. Resolves to the number of bytes written.

  • writeSync(p: Uint8Array): number

    Writes the given data to the buffer.

Enums

E

A enum which defines the seek mode for IO related APIs that support seeking.

Functions

f
copy(
src: Reader,
dst: Writer,
options?: { bufSize?: number; }
): Promise<number>

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.

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

Turns a Reader into an async iterator.

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

Turns a ReaderSync into an iterator.

f
readAll(reader: Reader): Promise<Uint8Array>

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

f
readAllSync(reader: ReaderSync): Uint8Array

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

f
readerFromStreamReader(streamReader: ReadableStreamDefaultReader<Uint8Array>): Reader
f
toReadableStream(
reader: Reader | (Reader & Closer),
options?: ToReadableStreamOptions
): ReadableStream<Uint8Array>

Create a ReadableStream of Uint8Arrays from a Reader.

f
toWritableStream(
writer: Writer,
options?: toWritableStreamOptions
): WritableStream<Uint8Array>

Create a WritableStream from a Writer.

f
writeAll(
writer: Writer,
data: Uint8Array
): Promise<void>

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

f
writeAllSync(
writer: WriterSync,
data: Uint8Array
): void

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

Interfaces

I

An abstract interface which when implemented provides an interface to close files/resources that were previously opened.

  • close(): void

    Closes the resource, "freeing" the backing file/resource.

I

An abstract interface which when implemented provides an interface to read bytes into an array buffer asynchronously.

  • read(p: Uint8Array): Promise<number | null>

    Reads up to p.byteLength bytes into p. It resolves to the number of bytes read (0 < n <= p.byteLength) and rejects if any error encountered. Even if read() resolves to n < p.byteLength, it may use all of p as scratch space during the call. If some data is available but not p.byteLength bytes, read() conventionally resolves to what is available instead of waiting for more.

I

An abstract interface which when implemented provides an interface to read bytes into an array buffer synchronously.

  • readSync(p: Uint8Array): number | null

    Reads up to p.byteLength bytes into p. It resolves to the number of bytes read (0 < n <= p.byteLength) and rejects if any error encountered. Even if read() returns n < p.byteLength, it may use all of p as scratch space during the call. If some data is available but not p.byteLength bytes, read() conventionally returns what is available instead of waiting for more.

I

An abstract interface which when implemented provides an interface to seek within an open file/resource asynchronously.

  • seek(
    offset: number | bigint,
    whence: SeekMode
    ): Promise<number>

    Seek sets the offset for the next read() or write() to offset, interpreted according to whence: Start means relative to the start of the file, Current means relative to the current offset, and End means relative to the end. Seek resolves to the new offset relative to the start of the file.

I

An abstract interface which when implemented provides an interface to seek within an open file/resource synchronously.

  • seekSync(
    offset: number | bigint,
    whence: SeekMode
    ): number

    Seek sets the offset for the next readSync() or writeSync() to offset, interpreted according to whence: Start means relative to the start of the file, Current means relative to the current offset, and End means relative to the end.

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

  • strategy: QueuingStrategy<Uint8Array>

    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.

I

An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource asynchronously.

  • write(p: Uint8Array): Promise<number>

    Writes p.byteLength bytes from p to the underlying data stream. It resolves to the number of bytes written from p (0 <= n <= p.byteLength) or reject with the error encountered that caused the write to stop early. write() must reject with a non-null error if would resolve to n < p.byteLength. write() must not modify the slice data, even temporarily.

I

An abstract interface which when implemented provides an interface to write bytes from an array buffer to a file/resource synchronously.

  • writeSync(p: Uint8Array): number

    Writes p.byteLength bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= p.byteLength) and any error encountered that caused the write to stop early. writeSync() must throw a non-null error if it returns n < p.byteLength. writeSync() must not modify the slice data, even temporarily.

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/io

Import symbol

import * as mod from "@std/io";
or

Import directly with a jsr specifier

import * as mod from "jsr:@std/io";