summaryrefslogtreecommitdiff
path: root/cli/js/read_text_file.ts
blob: 3423b26b8829d74eae67224b13a56ecfbbc435f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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);
}