support for file-system operations;
authorwenzelm
Wed, 02 Mar 2022 21:53:17 +0100
changeset 75190 fa9ca4563d72
parent 75189 f304a2a5080f
child 75191 fbff7bfd5802
support for file-system operations;
src/Tools/VSCode/extension/src/file.ts
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Tools/VSCode/extension/src/file.ts	Wed Mar 02 21:53:17 2022 +0100
@@ -0,0 +1,25 @@
+/*  Author:     Makarius
+
+File-system operations (see Pure/General/file.scala)
+*/
+
+'use strict';
+
+import * as fs from 'fs/promises'
+import { Buffer } from 'buffer'
+
+
+export async function read_bytes(path: string): Promise<Buffer>
+{
+    return fs.readFile(path)
+}
+
+export async function read(path: string): Promise<string>
+{
+    return read_bytes(path).then(buffer => buffer.toString())
+}
+
+export async function read_json<T>(path: string): Promise<T>
+{
+    return read(path).then(JSON.parse) as Promise<T>
+}