2020-04-28 01:35:20 -04:00
|
|
|
import { open, openSync } from "./files.ts";
|
|
|
|
import { readAll, readAllSync } from "./buffer.ts";
|
|
|
|
|
2020-06-11 12:36:20 -04:00
|
|
|
export function readTextFileSync(path: string | URL): string {
|
2020-04-28 01:35:20 -04:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
const file = openSync(path);
|
|
|
|
const content = readAllSync(file);
|
|
|
|
file.close();
|
|
|
|
return decoder.decode(content);
|
|
|
|
}
|
|
|
|
|
2020-06-11 12:36:20 -04:00
|
|
|
export async function readTextFile(path: string | URL): Promise<string> {
|
2020-04-28 01:35:20 -04:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
const file = await open(path);
|
|
|
|
const content = await readAll(file);
|
|
|
|
file.close();
|
|
|
|
return decoder.decode(content);
|
|
|
|
}
|