W3cubDocs

/Deno

Deno.readFile

Reads and resolves to the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required. Reading a directory returns an empty data array.

const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello.txt");
console.log(decoder.decode(data));

Requires allow-read permission.

function readFile(path: string | URL, options?: ReadFileOptions): Promise<Uint8Array>;
readFile(path: string | URL, options?: ReadFileOptions): Promise<Uint8Array>

Parameters

path: string | URL
options?: ReadFileOptions optional

Return Type

Promise<Uint8Array>

© 2018–2021 the Deno authors
https://doc.deno.land/deno/stable/~/Deno.readFile