Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Deno.readSync

Synchronously read from a resource ID (rid) into an array buffer (buffer).

Returns either the number of bytes read during the operation or EOF (null) if there was nothing more to read.

It is possible for a read to successfully return with 0 bytes. This does not indicate EOF.

This function is one of the lowest level APIs and most users should not work with this directly, but rather use readAllSync() from https://deno.land/std/streams/conversion.ts instead.

It is not guaranteed that the full buffer will be read in a single call.

// if "/foo/bar.txt" contains the text "hello world":
const file = Deno.openSync("/foo/bar.txt");
const buf = new Uint8Array(100);
const numberOfBytesRead = Deno.readSync(file.rid, buf); // 11 bytes
const text = new TextDecoder().decode(buf);  // "hello world"
Deno.close(file.rid);
function readSync(rid: number, buffer: Uint8Array): number | null;
§
readSync(rid: number, buffer: Uint8Array): number | null
[src]

§Parameters

§
rid: number
[src]
§
buffer: Uint8Array
[src]

§Return Type

§
number | null
[src]