@pagepocket/uni-fs 0.4.0 → 0.4.2
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/README.md +34 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @pagepocket/uni-fs
|
|
2
|
+
|
|
3
|
+
Unified filesystem helpers that work in Node and OPFS (Origin Private File System).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @pagepocket/uni-fs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
write,
|
|
16
|
+
readAsURL,
|
|
17
|
+
readText,
|
|
18
|
+
readBinary,
|
|
19
|
+
exists,
|
|
20
|
+
delete as deleteFile
|
|
21
|
+
} from "@pagepocket/uni-fs";
|
|
22
|
+
|
|
23
|
+
await write("snapshots/page", "html", "<html>...</html>");
|
|
24
|
+
const url = await readAsURL("snapshots/page", "html");
|
|
25
|
+
const text = await readText("snapshots/page", "html");
|
|
26
|
+
const bytes = await readBinary("snapshots/page", "html");
|
|
27
|
+
const ok = await exists("snapshots/page", "html");
|
|
28
|
+
await deleteFile("snapshots/page", "html");
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Behavior
|
|
32
|
+
|
|
33
|
+
- In browsers/Service Workers with OPFS, `readAsURL` returns a `data:` URL.
|
|
34
|
+
- In Node, `readAsURL` returns a file path beginning with `/`.
|
package/package.json
CHANGED