75190
|
1 |
/* Author: Makarius
|
|
2 |
|
|
3 |
File-system operations (see Pure/General/file.scala)
|
|
4 |
*/
|
|
5 |
|
|
6 |
'use strict';
|
|
7 |
|
|
8 |
import * as fs from 'fs/promises'
|
|
9 |
import { Buffer } from 'buffer'
|
|
10 |
|
|
11 |
|
|
12 |
export async function read_bytes(path: string): Promise<Buffer>
|
|
13 |
{
|
|
14 |
return fs.readFile(path)
|
|
15 |
}
|
|
16 |
|
|
17 |
export async function read(path: string): Promise<string>
|
|
18 |
{
|
|
19 |
return read_bytes(path).then(buffer => buffer.toString())
|
|
20 |
}
|
|
21 |
|
|
22 |
export async function read_json<T>(path: string): Promise<T>
|
|
23 |
{
|
|
24 |
return read(path).then(JSON.parse) as Promise<T>
|
|
25 |
}
|