1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-01 09:24:20 -04:00
denoland-deno/cli/js/read_text_file.ts

19 lines
542 B
TypeScript
Raw Normal View History

import { open, openSync } from "./files.ts";
import { readAll, readAllSync } from "./buffer.ts";
export function readTextFileSync(path: string): string {
const decoder = new TextDecoder();
const file = openSync(path);
const content = readAllSync(file);
file.close();
return decoder.decode(content);
}
export async function readTextFile(path: string): Promise<string> {
const decoder = new TextDecoder();
const file = await open(path);
const content = await readAll(file);
file.close();
return decoder.decode(content);
}