forked from solidjs-community/solid-primitives
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadapter-tauri.ts
More file actions
34 lines (33 loc) · 1.47 KB
/
adapter-tauri.ts
File metadata and controls
34 lines (33 loc) · 1.47 KB
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
import type { BaseDirectory, FileEntry, FsDirOptions } from "@tauri-apps/api/fs";
export const makeTauriFileSystem = (options: FsDirOptions = { dir: 22 as BaseDirectory.AppData }) =>
(taurifs =>
taurifs
? {
async: true as const,
getType: (path: string) =>
taurifs.exists(path, options).then((present: boolean) =>
present
? taurifs
.readdir(path)
.then(() => "dir" as const)
.catch(() => "file" as const)
: null,
),
mkdir: (path: string) => taurifs.createDir(path, { ...options, recursive: true }),
readdir: (path: string) =>
taurifs.readdir(path, options).then((entries: FileEntry[]) =>
entries.reduce((list, entry) => {
entry.name && list.push(entry.name);
return list;
}, [] as string[]),
),
readFile: (path: string) => taurifs.readTextFile(path, options),
rename: (previous: string, next: string) => taurifs.renameFile(previous, next),
rm: (path: string) =>
taurifs
.readdir(path)
.then(() => taurifs.removeDir(path, { ...options, recursive: true }))
.catch(() => taurifs.removeFile(path, options)),
writeFile: (path: string, data: string) => taurifs.writeTextFile(path, data),
}
: null)((globalThis as any).__TAURI__?.fs);