Module

std/io/mod.ts>Reader

Deno standard library
Go to Latest
interface Reader
import { type Reader } from "https://dotland.deno.dev/std@0.215.0/io/mod.ts";

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

Methods

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.

When read() encounters end-of-file condition, it resolves to EOF (null).

When read() encounters an error, it rejects with an error.

Callers should always process the n > 0 bytes returned before considering the EOF (null). Doing so correctly handles I/O errors that happen after reading some bytes and also both of the allowed EOF behaviors.

Implementations should not retain a reference to p.

Use iterateReader() from https://deno.land/std@0.215.0/streams/iterate_reader.ts to turn a Reader into an AsyncIterator.

import Reader
import { Reader } from "https://dotland.deno.dev/std@0.215.0/io/mod.ts";

A LimitedReader reads from reader but limits the amount of data returned to just limit bytes. Each call to read updates limit to reflect the new amount remaining. read returns null when limit <= 0 or when the underlying reader returns null.