Skip to main content

@std/io@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
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 Deno's readers, writers, and web streams.

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.

  • 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
    No documentation available
  • 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>

    NOTE: This methods writes bytes synchronously; it's provided for compatibility with Writer interface.

  • writeSync(p: Uint8Array): number
    No documentation available
c
BufferFullError(partial: Uint8Array)
No documentation available
  • name: string
    No documentation available
c
BufReader(
rd: Reader,
size?: number
)
No documentation available
  • buffered(): number
    No documentation available
  • create(
    r: Reader,
    size?: number
    ): BufReader

    return new BufReader unless r is BufReader

  • peek(n: number): Promise<Uint8Array | null>

    peek() returns the next n bytes without advancing the reader. The bytes stop being valid at the next read call.

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

    reads data into p. It returns the number of bytes read into p. The bytes are taken from at most one Read on the underlying Reader, hence n may be less than len(p). To read exactly len(p) bytes, use io.ReadFull(b, p).

  • readByte(): Promise<number | null>

    Returns the next byte [0, 255] or null.

  • readFull(p: Uint8Array): Promise<Uint8Array | null>

    reads exactly p.length bytes into p.

  • readLine(): Promise<ReadLineResult | null>

    readLine() is a low-level line-reading primitive. Most callers should use readString('\n') instead or use a Scanner.

  • readSlice(delim: number): Promise<Uint8Array | null>

    readSlice() reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read.

  • readString(delim: string): Promise<string | null>

    readString() reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often null). ReadString returns err !== null if and only if the returned data does not end in delim. For simple uses, a Scanner may be more convenient.

  • reset(r: Reader): void

    Discards any buffered data, resets all state, and switches the buffered reader to read from r.

  • size(): number

    Returns the size of the underlying buffer in bytes.

c
BufWriter(
writer: Writer,
size?: number
)

BufWriter implements buffering for an deno.Writer object. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes, and flush(), will return the error. After all data has been written, the client should call the flush() method to guarantee all data has been forwarded to the underlying deno.Writer.

  • create(
    writer: Writer,
    size?: number
    ): BufWriter

    return new BufWriter unless writer is BufWriter

  • flush(): Promise<void>

    Flush writes any buffered data to the underlying io.Writer.

  • reset(w: Writer): void

    Discards any unflushed buffered data, clears any error, and resets buffer to write its output to w.

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

    Writes the contents of data into the buffer. If the contents won't fully fit into the buffer, those bytes that are copied into the buffer will be flushed to the writer and the remaining bytes are then copied into the now empty buffer.

c
BufWriterSync(
writer: WriterSync,
size?: number
)

BufWriterSync implements buffering for a deno.WriterSync object. If an error occurs writing to a WriterSync, no more data will be accepted and all subsequent writes, and flush(), will return the error. After all data has been written, the client should call the flush() method to guarantee all data has been forwarded to the underlying deno.WriterSync.

  • create(
    writer: WriterSync,
    size?: number
    ): BufWriterSync

    return new BufWriterSync unless writer is BufWriterSync

  • flush(): void

    Flush writes any buffered data to the underlying io.WriterSync.

  • reset(w: WriterSync): void

    Discards any unflushed buffered data, clears any error, and resets buffer to write its output to w.

  • writeSync(data: Uint8Array): number

    Writes the contents of data into the buffer. If the contents won't fully fit into the buffer, those bytes that can are copied into the buffer, the buffer is the flushed to the writer and the remaining bytes are copied into the now empty buffer.

c
LimitedReader(
reader: Reader,
limit: number
)
No documentation available
  • read(p: Uint8Array): Promise<number | null>
    No documentation available
c
MultiReader(readers: Reader[])

Reader utility for combining multiple readers

  • read(p: Uint8Array): Promise<number | null>
    No documentation available
c
No documentation available
  • name: string
    No documentation available
  • partial: Uint8Array
    No documentation available
c
StringReader(s: string)

Reader utility for strings.

c
StringWriter(base?: string)

Writer utility for buffering string chunks.

  • toString(): string
    No documentation available
  • write(p: Uint8Array): Promise<number>
    No documentation available
  • writeSync(p: Uint8Array): number
    No documentation available

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
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
toReadableStream(
reader: Reader | (Reader & Closer),
unnamed 1?: ToReadableStreamOptions
): ReadableStream<Uint8Array>

Create a ReadableStream of Uint8Arrays from a Reader.

f
toWritableStream(
writer: Writer,
unnamed 1?: 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).

f
copyN(
r: Reader,
dest: Writer,
size: number
): Promise<number>

Copy N size at the most. If read size is lesser than N, then returns nread

f
readDelim(
reader: Reader,
delim: Uint8Array
): AsyncIterableIterator<Uint8Array>

Read delimited bytes from a Reader.

f
readInt(buf: BufReader): Promise<number | null>

Read big endian 32bit integer from BufReader

f
readLines(
reader: Reader,
decoderOpts?: { encoding?: string; fatal?: boolean; ignoreBOM?: boolean; }
): AsyncIterableIterator<string>

Read strings line-by-line from a Reader.

f
readLong(buf: BufReader): Promise<number | null>

Read big endian 64bit long from BufReader

f
readRange(
r: Reader & Deno.Seeker,
range: ByteRange
): Promise<Uint8Array>

Read a range of bytes from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.

f
readRangeSync(
r: ReaderSync & Deno.SeekerSync,
range: ByteRange
): Uint8Array

Read a range of bytes synchronously from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.

f
readShort(buf: BufReader): Promise<number | null>

Read big endian 16bit short from BufReader

f
readStringDelim(
reader: Reader,
delim: string,
decoderOpts?: { encoding?: string; fatal?: boolean; ignoreBOM?: boolean; }
): AsyncIterableIterator<string>

Read Reader chunk by chunk, splitting based on delimiter.

f
sliceLongToBytes(
d: number,
dest?: number[]
): number[]

Slice number into 64bit big endian byte array

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

Options for toReadableStream.

  • 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: QueuingStrategy<Uint8Array>

    The queuing strategy to create the ReadableStream with.

I

Options for toWritableStream.

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

I
No documentation available
  • end: number

    The 0 based index of the end byte for a range, which is inclusive.

  • start: number

    The 0 based index of the start byte for a range.

I

Result type returned by of BufReader.readLine().

  • line: Uint8Array
    No documentation available
  • more: boolean
    No documentation available
buf_reader

Classes

c
BufferFullError(partial: Uint8Array)
No documentation available
  • name: string
    No documentation available
c
BufReader(
rd: Reader,
size?: number
)
No documentation available
  • buffered(): number
    No documentation available
  • create(
    r: Reader,
    size?: number
    ): BufReader

    return new BufReader unless r is BufReader

  • peek(n: number): Promise<Uint8Array | null>

    peek() returns the next n bytes without advancing the reader. The bytes stop being valid at the next read call.

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

    reads data into p. It returns the number of bytes read into p. The bytes are taken from at most one Read on the underlying Reader, hence n may be less than len(p). To read exactly len(p) bytes, use io.ReadFull(b, p).

  • readByte(): Promise<number | null>

    Returns the next byte [0, 255] or null.

  • readFull(p: Uint8Array): Promise<Uint8Array | null>

    reads exactly p.length bytes into p.

  • readLine(): Promise<ReadLineResult | null>

    readLine() is a low-level line-reading primitive. Most callers should use readString('\n') instead or use a Scanner.

  • readSlice(delim: number): Promise<Uint8Array | null>

    readSlice() reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the buffer. The bytes stop being valid at the next read.

  • readString(delim: string): Promise<string | null>

    readString() reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often null). ReadString returns err !== null if and only if the returned data does not end in delim. For simple uses, a Scanner may be more convenient.

  • reset(r: Reader): void

    Discards any buffered data, resets all state, and switches the buffered reader to read from r.

  • size(): number

    Returns the size of the underlying buffer in bytes.

c
No documentation available
  • name: string
    No documentation available
  • partial: Uint8Array
    No documentation available

Interfaces

I

Result type returned by of BufReader.readLine().

  • line: Uint8Array
    No documentation available
  • more: boolean
    No documentation available
buf_writer

Classes

c
BufWriter(
writer: Writer,
size?: number
)

BufWriter implements buffering for an deno.Writer object. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes, and flush(), will return the error. After all data has been written, the client should call the flush() method to guarantee all data has been forwarded to the underlying deno.Writer.

  • create(
    writer: Writer,
    size?: number
    ): BufWriter

    return new BufWriter unless writer is BufWriter

  • flush(): Promise<void>

    Flush writes any buffered data to the underlying io.Writer.

  • reset(w: Writer): void

    Discards any unflushed buffered data, clears any error, and resets buffer to write its output to w.

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

    Writes the contents of data into the buffer. If the contents won't fully fit into the buffer, those bytes that are copied into the buffer will be flushed to the writer and the remaining bytes are then copied into the now empty buffer.

c
BufWriterSync(
writer: WriterSync,
size?: number
)

BufWriterSync implements buffering for a deno.WriterSync object. If an error occurs writing to a WriterSync, no more data will be accepted and all subsequent writes, and flush(), will return the error. After all data has been written, the client should call the flush() method to guarantee all data has been forwarded to the underlying deno.WriterSync.

  • create(
    writer: WriterSync,
    size?: number
    ): BufWriterSync

    return new BufWriterSync unless writer is BufWriterSync

  • flush(): void

    Flush writes any buffered data to the underlying io.WriterSync.

  • reset(w: WriterSync): void

    Discards any unflushed buffered data, clears any error, and resets buffer to write its output to w.

  • writeSync(data: Uint8Array): number

    Writes the contents of data into the buffer. If the contents won't fully fit into the buffer, those bytes that can are copied into the buffer, the buffer is the flushed to the writer and the remaining bytes are copied into the now empty buffer.

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.

  • 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
    No documentation available
  • 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>

    NOTE: This methods writes bytes synchronously; it's provided for compatibility with Writer interface.

  • writeSync(p: Uint8Array): number
    No documentation available
copy

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.

copy_n

Functions

f
copyN(
r: Reader,
dest: Writer,
size: number
): Promise<number>

Copy N size at the most. If read size is lesser than N, then returns nread

limited_reader

Classes

c
LimitedReader(
reader: Reader,
limit: number
)
No documentation available
  • read(p: Uint8Array): Promise<number | null>
    No documentation available
multi_reader

Classes

c
MultiReader(readers: Reader[])

Reader utility for combining multiple readers

  • read(p: Uint8Array): Promise<number | null>
    No documentation available
read_all

Functions

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.

read_delim

Functions

f
readDelim(
reader: Reader,
delim: Uint8Array
): AsyncIterableIterator<Uint8Array>

Read delimited bytes from a Reader.

read_int

Functions

f
readInt(buf: BufReader): Promise<number | null>

Read big endian 32bit integer from BufReader

read_lines

Functions

f
readLines(
reader: Reader,
decoderOpts?: { encoding?: string; fatal?: boolean; ignoreBOM?: boolean; }
): AsyncIterableIterator<string>

Read strings line-by-line from a Reader.

read_long

Functions

f
readLong(buf: BufReader): Promise<number | null>

Read big endian 64bit long from BufReader

read_range

Functions

f
readRange(
r: Reader & Deno.Seeker,
range: ByteRange
): Promise<Uint8Array>

Read a range of bytes from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.

f
readRangeSync(
r: ReaderSync & Deno.SeekerSync,
range: ByteRange
): Uint8Array

Read a range of bytes synchronously from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.

Interfaces

I
No documentation available
  • end: number

    The 0 based index of the end byte for a range, which is inclusive.

  • start: number

    The 0 based index of the start byte for a range.

read_short

Functions

f
readShort(buf: BufReader): Promise<number | null>

Read big endian 16bit short from BufReader

read_string_delim

Functions

f
readStringDelim(
reader: Reader,
delim: string,
decoderOpts?: { encoding?: string; fatal?: boolean; ignoreBOM?: boolean; }
): AsyncIterableIterator<string>

Read Reader chunk by chunk, splitting based on delimiter.

slice_long_to_bytes

Functions

f
sliceLongToBytes(
d: number,
dest?: number[]
): number[]

Slice number into 64bit big endian byte array

string_reader

Classes

c
StringReader(s: string)

Reader utility for strings.

string_writer

Classes

c
StringWriter(base?: string)

Writer utility for buffering string chunks.

  • toString(): string
    No documentation available
  • write(p: Uint8Array): Promise<number>
    No documentation available
  • writeSync(p: Uint8Array): number
    No documentation available
to_readable_stream

Functions

f
toReadableStream(
reader: Reader | (Reader & Closer),
unnamed 1?: ToReadableStreamOptions
): ReadableStream<Uint8Array>

Create a ReadableStream of Uint8Arrays from a Reader.

Interfaces

I

Options for toReadableStream.

  • 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: QueuingStrategy<Uint8Array>

    The queuing strategy to create the ReadableStream with.

to_writable_stream

Functions

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

Create a WritableStream from a Writer.

Interfaces

I

Options for toWritableStream.

  • autoClose: boolean

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

types

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

write_all

Functions

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

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.