1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00
denoland-deno/cli/js/read_text_file.ts
2020-07-06 21:45:39 -04:00

20 lines
634 B
TypeScript

// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { open, openSync } from "./files.ts";
import { readAll, readAllSync } from "./buffer.ts";
export function readTextFileSync(path: string | URL): string {
const file = openSync(path);
const contents = readAllSync(file);
file.close();
const decoder = new TextDecoder();
return decoder.decode(contents);
}
export async function readTextFile(path: string | URL): Promise<string> {
const file = await open(path);
const contents = await readAll(file);
file.close();
const decoder = new TextDecoder();
return decoder.decode(contents);
}