Skip to content

Commit f0f398f

Browse files
committed
refactor: Created fs dir and moved async fs stuff there
1 parent 0f47881 commit f0f398f

File tree

5 files changed

+37
-33
lines changed

5 files changed

+37
-33
lines changed

src/fs/exists.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { access } from "fs";
2+
3+
export function exists(path: string): Promise<boolean> {
4+
return new Promise((resolve, reject) => {
5+
access(path, err => (err ? reject(err) : resolve(true)));
6+
});
7+
}

src/fs/readdir.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { readdir as fsReaddir } from "fs";
2+
3+
export function readdir(path: string): Promise<string[]> {
4+
return new Promise((resolve, reject) => {
5+
fsReaddir(path, (err, files) => {
6+
if (err) {
7+
reject(err);
8+
}
9+
10+
resolve(files);
11+
});
12+
});
13+
}

src/fs/stat.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { stat as fsStat, Stats } from "fs";
2+
3+
export function stat(filePath: string): Promise<Stats> {
4+
return new Promise((resolve, reject) => {
5+
fsStat(filePath, (err, stats) => {
6+
if (err) {
7+
reject(err);
8+
}
9+
10+
resolve(stats);
11+
});
12+
});
13+
}

src/model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import {
3131
isDescendant,
3232
normalizePath
3333
} from "./util";
34-
import { exists, readDir, stat } from "./util/async_fs";
34+
import { exists } from "./fs/exists";
35+
import { readdir } from "./fs/readdir";
36+
import { stat } from "./fs/stat";
3537
import { matchAll } from "./util/globMatch";
3638

3739
export class Model implements IDisposable {
@@ -336,7 +338,7 @@ export class Model implements IDisposable {
336338
let files: string[] | Buffer[] = [];
337339

338340
try {
339-
files = await readDir(path);
341+
files = await readdir(path);
340342
} catch (error) {
341343
return;
342344
}

src/util/async_fs.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)