summaryrefslogtreecommitdiff
path: root/cli/js/read_text_file.ts
diff options
context:
space:
mode:
authorDivya <hello@shortdiv.com>2020-04-28 00:35:20 -0500
committerGitHub <noreply@github.com>2020-04-28 01:35:20 -0400
commitde751e5221cd2eafbdd9cddfb58b0619d74c0504 (patch)
tree10af8c5b70fc6b57f4a3247ec3367bf5847f195b /cli/js/read_text_file.ts
parent2fc5878668d8f08ec6989d07e79125d640a73d43 (diff)
fix(#4769) Adds readTextFile, writeTextFile, with sync counterparts (#4901)
Diffstat (limited to 'cli/js/read_text_file.ts')
-rw-r--r--cli/js/read_text_file.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/cli/js/read_text_file.ts b/cli/js/read_text_file.ts
new file mode 100644
index 000000000..3423b26b8
--- /dev/null
+++ b/cli/js/read_text_file.ts
@@ -0,0 +1,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);
+}