Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/deno/cli/js/lib.deno.ns.d.ts>Deno.readSync

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.readSync
import { Deno } from "https://deno.land/x/deno@v1.0.0/cli/js/lib.deno.ns.d.ts";
const { readSync } = Deno;

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.

 // 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);

Parameters

rid: number
buffer: Uint8Array

Returns

number | null