1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-12 02:27:46 -05:00
denoland-deno/cli/js/read_text_file.ts

21 lines
634 B
TypeScript
Raw Normal View History

2020-07-06 21:45:39 -04:00
// 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);
2020-07-06 21:45:39 -04:00
const contents = readAllSync(file);
file.close();
2020-07-06 21:45:39 -04:00
const decoder = new TextDecoder();
return decoder.decode(contents);
}
export async function readTextFile(path: string | URL): Promise<string> {
const file = await open(path);
2020-07-06 21:45:39 -04:00
const contents = await readAll(file);
file.close();
2020-07-06 21:45:39 -04:00
const decoder = new TextDecoder();
return decoder.decode(contents);
}