Deno API

Deno.readFile

export function readFile(path: string): Promise<Uint8Array>;

使用实例:

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

Deno.writeFile

export function writeFile(
    path: string,
    data: Uint8Array,
    options?: WriteFileOptions
): Promise<void>

使用实例:

const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
// overwrite "hello1.txt" or create it
await Deno.writeFile("hello1.txt", data);
// only works if "hello2.txt" exists
await Deno.writeFile("hello2.txt", data, {create: false});
// set permissions on new file
await Deno.writeFile("hello3.txt", data, {mode: 0o777});
// add data to end of the file
await Deno.writeFile("hello4.txt", data, {append: true});

最后更新于