blob: 02c9fe61197d079f43ca9368cd4d5a547c9a47fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
// 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);
const contents = readAllSync(file);
file.close();
const decoder = new TextDecoder();
return decoder.decode(contents);
}
export async function readTextFile(path: string | URL): Promise<string> {
const file = await open(path);
const contents = await readAll(file);
file.close();
const decoder = new TextDecoder();
return decoder.decode(contents);
}
|