-
Notifications
You must be signed in to change notification settings - Fork 742
Expand file tree
/
Copy pathfs.ts
More file actions
36 lines (34 loc) · 881 Bytes
/
fs.ts
File metadata and controls
36 lines (34 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { walk, type WalkEntry, type WalkOptions } from "@std/fs/walk";
export interface FsAdapter {
cwd(): string;
walk(
root: string | URL,
options?: WalkOptions,
): AsyncIterableIterator<WalkEntry>;
isDirectory(path: string | URL): Promise<boolean>;
mkdirp(dir: string): Promise<void>;
readFile(path: string | URL): Promise<Uint8Array>;
}
export const fsAdapter: FsAdapter = {
walk,
cwd: Deno.cwd,
async isDirectory(path) {
try {
const stat = await Deno.stat(path);
return stat.isDirectory;
} catch (err) {
if (err instanceof Deno.errors.NotFound) return false;
throw err;
}
},
async mkdirp(dir: string) {
try {
await Deno.mkdir(dir, { recursive: true });
} catch (err) {
if (!(err instanceof Deno.errors.AlreadyExists)) {
throw err;
}
}
},
readFile: Deno.readFile,
};