Skip to content

Commit fbbcd06

Browse files
committed
Add promise functions for fs
1 parent 92d70e9 commit fbbcd06

File tree

1 file changed

+30
-0
lines changed
  • packages/app/src/app/utils

1 file changed

+30
-0
lines changed

packages/app/src/app/utils/fs.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import * as fs from 'fs';
2+
3+
export function readFilePromise(
4+
path: string | number | Buffer | import('url').URL,
5+
options?: { encoding?: string; flag?: string }
6+
): Promise<string | Buffer> {
7+
return new Promise((resolve, reject) => {
8+
fs.readFile(path, options, (err, data) => {
9+
if (err) {
10+
reject(err);
11+
return;
12+
}
13+
14+
resolve(data);
15+
});
16+
});
17+
}
18+
19+
export function readdirPromise(path: fs.PathLike): Promise<string[]> {
20+
return new Promise((resolve, reject) => {
21+
fs.readdir(path, (err, files) => {
22+
if (err) {
23+
reject(err);
24+
return;
25+
}
26+
27+
resolve(files);
28+
});
29+
});
30+
}

0 commit comments

Comments
 (0)