Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/tsc/dts/lib.deno.ns.d.ts>Deno.ReaderSync

A modern runtime for JavaScript and TypeScript.
Go to Latest
interface Deno.ReaderSync
import { type Deno } from "https://deno.land/x/deno@v1.36.0/cli/tsc/dts/lib.deno.ns.d.ts";
const { ReaderSync } = Deno;

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

Methods

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 readSync() 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, readSync() conventionally returns what is available instead of waiting for more.

When readSync() encounters end-of-file condition, it returns EOF (null).

When readSync() encounters an error, it throws 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 itereateReaderSync from from std/streams/iterate_reader.ts to turn a ReaderSync into an Iterator.