@data-fair/lib-node 2.10.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fs.d.ts +1 -1
- package/fs.js +16 -11
- package/package.json +1 -1
package/fs.d.ts
CHANGED
package/fs.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mkdir, readdir, unlink, access } from 'node:fs/promises';
|
|
2
|
+
import { sep, join } from 'node:path';
|
|
2
3
|
export async function ensureDir(dir) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const parts = dir.split(sep);
|
|
5
|
+
for (let i = 0; i < parts.length; i++) {
|
|
6
|
+
const partialDir = join(...parts.slice(0, i + 1));
|
|
7
|
+
try {
|
|
8
|
+
await mkdir(partialDir);
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
if (err.code !== 'EEXIST')
|
|
12
|
+
throw err;
|
|
13
|
+
}
|
|
9
14
|
}
|
|
10
15
|
}
|
|
11
16
|
export async function emptyDir(dir) {
|
|
12
17
|
await ensureDir(dir);
|
|
13
|
-
const files = await
|
|
18
|
+
const files = await readdir(dir);
|
|
14
19
|
for (const file of files) {
|
|
15
|
-
await
|
|
20
|
+
await unlink(`${dir}/${file}`);
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
|
-
export async function
|
|
23
|
+
export async function exists(file) {
|
|
19
24
|
try {
|
|
20
|
-
await
|
|
25
|
+
await access(file);
|
|
21
26
|
}
|
|
22
27
|
catch (err) {
|
|
23
28
|
if (err.code === 'ENOENT')
|