2020-07-07 04:45:39 +03:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
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 file = openSync(path);
|
2020-07-07 04:45:39 +03:00
|
|
|
const contents = readAllSync(file);
|
2020-04-28 00:35:20 -05:00
|
|
|
file.close();
|
2020-07-07 04:45:39 +03:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
return decoder.decode(contents);
|
2020-04-28 00:35:20 -05:00
|
|
|
}
|
|
|
|
|
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 file = await open(path);
|
2020-07-07 04:45:39 +03:00
|
|
|
const contents = await readAll(file);
|
2020-04-28 00:35:20 -05:00
|
|
|
file.close();
|
2020-07-07 04:45:39 +03:00
|
|
|
const decoder = new TextDecoder();
|
|
|
|
return decoder.decode(contents);
|
2020-04-28 00:35:20 -05:00
|
|
|
}
|