@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 +52 -0
- package/dist/cjs/index.cjs +752 -0
- package/dist/cjs/index.cjs.map +10 -0
- package/dist/cjs/node-adapter.cjs +230 -0
- package/dist/cjs/node-adapter.cjs.map +10 -0
- package/dist/cjs/package.json +5 -0
- package/dist/mjs/index.mjs +708 -0
- package/dist/mjs/index.mjs.map +10 -0
- package/dist/mjs/node-adapter.mjs +186 -0
- package/dist/mjs/node-adapter.mjs.map +10 -0
- package/dist/mjs/package.json +5 -0
- package/dist/types/index.d.ts +70 -0
- package/dist/types/isolate.d.ts +308 -0
- package/dist/types/node-adapter.d.ts +24 -0
- package/package.json +41 -15
- package/CHANGELOG.md +0 -9
- package/src/fixtures/test-image.png +0 -0
- package/src/index.test.ts +0 -882
- package/src/index.ts +0 -997
- package/src/integration.test.ts +0 -288
- package/src/node-adapter.test.ts +0 -337
- package/src/node-adapter.ts +0 -300
- package/src/streaming.test.ts +0 -634
- package/tsconfig.json +0 -8
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
|
+
```
|