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