Skip to main content
Deno.read - Deno documentation
function Deno.read
read(
rid: number,
buffer: Uint8Array,
): Promise<number | null>
Deprecated

This will be removed in Deno 2.0. See the Deno 1.x to 2.x Migration Guide for migration instructions.

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

Resolves to 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 ReadableStream and toArrayBuffer 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":
using file = await Deno.open("/foo/bar.txt");
const buf = new Uint8Array(100);
const numberOfBytesRead = await Deno.read(file.rid, buf); // 11 bytes
const text = new TextDecoder().decode(buf);  // "hello world"

Parameters

rid: number
buffer: Uint8Array

Return Type

Promise<number | null>