@ricsam/isolate-fs 0.1.1 → 0.1.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 ADDED
@@ -0,0 +1,52 @@
1
+ # @ricsam/isolate-fs
2
+
3
+ File System Access API (OPFS-compatible).
4
+
5
+ ```typescript
6
+ import { setupFs } from "@ricsam/isolate-fs";
7
+
8
+ const handle = await setupFs(context, {
9
+ // Return a FileSystemHandler for the given directory path
10
+ getDirectory: async (path) => {
11
+ // Validate path access
12
+ if (!path.startsWith("/allowed")) {
13
+ throw new Error("Access denied");
14
+ }
15
+ return createNodeFileSystemHandler(`./sandbox${path}`);
16
+ },
17
+ });
18
+ ```
19
+
20
+ **Injected Globals:**
21
+ - `getDirectory(path)` - Entry point for file system access
22
+ - `FileSystemDirectoryHandle`, `FileSystemFileHandle`
23
+ - `FileSystemWritableFileStream`
24
+
25
+ **Usage in Isolate:**
26
+
27
+ ```javascript
28
+ // Get directory handle
29
+ const root = await getDirectory("/data");
30
+
31
+ // Read a file
32
+ const fileHandle = await root.getFileHandle("config.json");
33
+ const file = await fileHandle.getFile();
34
+ const text = await file.text();
35
+ const config = JSON.parse(text);
36
+
37
+ // Write a file
38
+ const outputHandle = await root.getFileHandle("output.txt", { create: true });
39
+ const writable = await outputHandle.createWritable();
40
+ await writable.write("Hello, World!");
41
+ await writable.close();
42
+
43
+ // Directory operations
44
+ const subDir = await root.getDirectoryHandle("subdir", { create: true });
45
+ await root.removeEntry("old-file.txt");
46
+ await root.removeEntry("old-dir", { recursive: true });
47
+
48
+ // Iterate directory
49
+ for await (const [name, handle] of root.entries()) {
50
+ console.log(name, handle.kind); // "file" or "directory"
51
+ }
52
+ ```