opfs-worker 2.1.0 → 2.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.
Files changed (111) hide show
  1. package/README.md +51 -37
  2. package/dist/BaseOPFS-Bu7FZtCb.cjs +2 -0
  3. package/dist/BaseOPFS-Bu7FZtCb.cjs.map +1 -0
  4. package/dist/{BaseOPFS-Cylz6ijk.js → BaseOPFS-C3NE4BKr.js} +804 -484
  5. package/dist/BaseOPFS-C3NE4BKr.js.map +1 -0
  6. package/dist/OPFSAsync-C0RsxCX5.cjs +2 -0
  7. package/dist/OPFSAsync-C0RsxCX5.cjs.map +1 -0
  8. package/dist/{OPFSAsync-BKSAJJeh.js → OPFSAsync-aeLUdIqd.js} +19 -19
  9. package/dist/OPFSAsync-aeLUdIqd.js.map +1 -0
  10. package/dist/OPFSFacade-BJv2yuWU.cjs +2 -0
  11. package/dist/OPFSFacade-BJv2yuWU.cjs.map +1 -0
  12. package/dist/OPFSFacade-DiogtQoq.js +308 -0
  13. package/dist/OPFSFacade-DiogtQoq.js.map +1 -0
  14. package/dist/OPFSSync-3qlSBYmz.cjs +2 -0
  15. package/dist/OPFSSync-3qlSBYmz.cjs.map +1 -0
  16. package/dist/{OPFSSync-CsSQkpk5.js → OPFSSync-CvSOswhW.js} +57 -57
  17. package/dist/OPFSSync-CvSOswhW.js.map +1 -0
  18. package/dist/assets/dedicated.worker-Bqqr9UBA.js.map +1 -0
  19. package/dist/core/BaseOPFS.d.ts +60 -9
  20. package/dist/core/BaseOPFS.d.ts.map +1 -1
  21. package/dist/core/OPFSAsync.d.ts.map +1 -1
  22. package/dist/core/OPFSSync.d.ts.map +1 -1
  23. package/dist/createOPFSAsync-B611B63X.js +10 -0
  24. package/dist/{createOPFSAsync-Y4Mg6qte.js.map → createOPFSAsync-B611B63X.js.map} +1 -1
  25. package/dist/createOPFSAsync-BATjJg8k.cjs +2 -0
  26. package/dist/{createOPFSAsync-BwKDmHsy.cjs.map → createOPFSAsync-BATjJg8k.cjs.map} +1 -1
  27. package/dist/createOPFSDedicated-DgudPTB8.js +2676 -0
  28. package/dist/createOPFSDedicated-DgudPTB8.js.map +1 -0
  29. package/dist/createOPFSDedicated-EmIwluQo.cjs +2597 -0
  30. package/dist/createOPFSDedicated-EmIwluQo.cjs.map +1 -0
  31. package/dist/{createOPFSShared-CGdd__PH.js → createOPFSShared-BWYln8jJ.js} +2 -2
  32. package/dist/{createOPFSShared-CGdd__PH.js.map → createOPFSShared-BWYln8jJ.js.map} +1 -1
  33. package/dist/{createOPFSShared-CskROt7U.cjs → createOPFSShared-DPJpCd7z.cjs} +2 -2
  34. package/dist/{createOPFSShared-CskROt7U.cjs.map → createOPFSShared-DPJpCd7z.cjs.map} +1 -1
  35. package/dist/dedicated.worker.js +1104 -790
  36. package/dist/dedicated.worker.js.map +1 -1
  37. package/dist/facade/OPFSFacade.d.ts +21 -3
  38. package/dist/facade/OPFSFacade.d.ts.map +1 -1
  39. package/dist/facade/createOPFSDedicated.d.ts +4 -2
  40. package/dist/facade/createOPFSDedicated.d.ts.map +1 -1
  41. package/dist/index.async.cjs +1 -1
  42. package/dist/index.async.js +33 -32
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.ts +1 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +44 -43
  47. package/dist/index.pure.cjs +1 -1
  48. package/dist/index.pure.js +38 -37
  49. package/dist/index.sharedworker.cjs +1 -1
  50. package/dist/index.sharedworker.js +34 -33
  51. package/dist/index.sync.cjs +1 -1
  52. package/dist/index.sync.d.ts +2 -0
  53. package/dist/index.sync.d.ts.map +1 -1
  54. package/dist/index.sync.js +34 -32
  55. package/dist/shared.worker.js +1101 -791
  56. package/dist/shared.worker.js.map +1 -1
  57. package/dist/types.d.ts +38 -5
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/utils/helpers.d.ts +13 -3
  60. package/dist/utils/helpers.d.ts.map +1 -1
  61. package/dist/worker/createDedicatedWorker.d.ts +8 -3
  62. package/dist/worker/createDedicatedWorker.d.ts.map +1 -1
  63. package/docs/README.md +13 -25
  64. package/docs/api/README.md +221 -0
  65. package/docs/api/file-descriptors.md +137 -0
  66. package/docs/guides/async.md +4 -4
  67. package/docs/guides/dedicated.md +10 -8
  68. package/docs/guides/hashing.md +3 -3
  69. package/docs/guides/pure.md +4 -4
  70. package/docs/guides/sharedworker.md +2 -2
  71. package/docs/guides/streaming.md +146 -12
  72. package/docs/guides/watching.md +3 -3
  73. package/docs/migration.md +10 -11
  74. package/docs/types.md +93 -155
  75. package/package.json +20 -9
  76. package/src/core/BaseOPFS.ts +194 -29
  77. package/src/core/OPFSAsync.ts +4 -5
  78. package/src/core/OPFSSync.ts +6 -7
  79. package/src/facade/OPFSFacade.ts +51 -4
  80. package/src/facade/createOPFSDedicated.ts +4 -2
  81. package/src/index.sync.ts +2 -0
  82. package/src/index.ts +1 -5
  83. package/src/types.ts +42 -3
  84. package/src/utils/helpers.ts +32 -6
  85. package/src/worker/createDedicatedWorker.ts +85 -7
  86. package/src/worker/dedicated.worker.ts +12 -1
  87. package/dist/BaseOPFS-BPw9AIQ-.cjs +0 -4
  88. package/dist/BaseOPFS-BPw9AIQ-.cjs.map +0 -1
  89. package/dist/BaseOPFS-Cylz6ijk.js.map +0 -1
  90. package/dist/OPFSAsync-BKSAJJeh.js.map +0 -1
  91. package/dist/OPFSAsync-s2P7y3sw.cjs +0 -2
  92. package/dist/OPFSAsync-s2P7y3sw.cjs.map +0 -1
  93. package/dist/OPFSFacade-DePnNRgt.cjs +0 -2
  94. package/dist/OPFSFacade-DePnNRgt.cjs.map +0 -1
  95. package/dist/OPFSFacade-XohWlHuu.js +0 -281
  96. package/dist/OPFSFacade-XohWlHuu.js.map +0 -1
  97. package/dist/OPFSSync-C7KBepe_.cjs +0 -2
  98. package/dist/OPFSSync-C7KBepe_.cjs.map +0 -1
  99. package/dist/OPFSSync-CsSQkpk5.js.map +0 -1
  100. package/dist/assets/dedicated.worker-nY3tK4zi.js.map +0 -1
  101. package/dist/createOPFSAsync-BwKDmHsy.cjs +0 -2
  102. package/dist/createOPFSAsync-Y4Mg6qte.js +0 -10
  103. package/dist/createOPFSDedicated-CsnV6MLP.js +0 -2333
  104. package/dist/createOPFSDedicated-CsnV6MLP.js.map +0 -1
  105. package/dist/createOPFSDedicated-pKTRWLdz.cjs +0 -2283
  106. package/dist/createOPFSDedicated-pKTRWLdz.cjs.map +0 -1
  107. package/docs/api/backend.md +0 -36
  108. package/docs/api/create.md +0 -82
  109. package/docs/api/facade.md +0 -52
  110. package/docs/choosing-a-mode.md +0 -41
  111. package/docs/file-descriptors.md +0 -695
@@ -1 +0,0 @@
1
- {"version":3,"file":"createOPFSDedicated-pKTRWLdz.cjs","sources":["../src/worker/createDedicatedWorker.ts","../src/facade/createOPFSDedicated.ts"],"sourcesContent":["import { wrap } from 'comlink';\n\nimport WorkerCtor from './dedicated.worker?worker&inline';\n\nimport type { OPFSOptions, OPFSSync } from '../types';\nimport type { Remote } from 'comlink';\n\nconst InlineWorker = WorkerCtor as new (options?: WorkerOptions) => Worker;\n\ntype RemoteOPFSSync = Remote<OPFSSync>;\n\nexport interface DedicatedWorkerOptions extends OPFSOptions {\n /**\n * URL of the worker script, e.g. `import url from 'opfs-worker/dedicated.worker.js?url'` (Vite).\n *\n * Defaults to the inlined worker (no URL needed). Pass an explicit url when you\n * prefer the self-contained file (strict CSP without `blob:`, or DIY hosting).\n */\n url?: string | URL;\n /** Bring your own Worker instance (overrides `url`) */\n worker?: Worker;\n}\n\nexport interface RawWorker {\n /** Comlink proxy to `OPFSSync` (bytes in / bytes out) */\n fs: RemoteOPFSSync;\n /** Underlying browser Worker */\n worker: Worker;\n /** Calls worker `dispose()` then `terminate()` */\n dispose: () => void;\n}\n\n/** A `BroadcastChannel` instance can't cross the wire — send its name instead. */\nfunction applyWorkerOptions(fs: Pick<RemoteOPFSSync, 'setOptions'>, options?: OPFSOptions): void {\n if (!options) {\n return;\n }\n\n if (options.broadcastChannel instanceof BroadcastChannel) {\n options.broadcastChannel = options.broadcastChannel.name;\n }\n\n void fs.setOptions(options);\n}\n\n/**\n * Internal helper: spawn a dedicated worker and wrap `OPFSSync` with Comlink.\n * Prefer {@link createOPFSDedicated}; access the proxy / Worker via\n * `facade.backend` / `facade.worker`.\n */\nexport function createDedicatedWorker(options: DedicatedWorkerOptions = {}): RawWorker {\n const { url, worker: providedWorker, ...fsOptions } = options;\n\n const worker = providedWorker\n ?? (url ? new Worker(url, { type: 'module' }) : new InlineWorker());\n const fs = wrap<RemoteOPFSSync>(worker);\n\n applyWorkerOptions(fs, fsOptions);\n\n return {\n fs,\n worker,\n dispose() {\n void (async() => {\n try {\n await fs.dispose();\n }\n finally {\n worker.terminate();\n }\n })();\n },\n };\n}\n","import { OPFSFacade } from './OPFSFacade';\nimport { createDedicatedWorker } from '../worker/createDedicatedWorker';\n\nimport type { DedicatedWorkerOptions } from '../worker/createDedicatedWorker';\n\n/**\n * Dedicated mode: start a dedicated worker and get a Node-like `fs` API\n * backed by `OPFSSync`.\n *\n * Prefer importing from `opfs-worker/sync` when you only need the worker backend\n * (avoids pulling `OPFSAsync` into the graph). Importing from `opfs-worker` works too.\n *\n * By default uses an inlined worker. Pass `url` / `worker` to load\n * `opfs-worker/dedicated.worker.js` instead (see {@link DedicatedWorkerOptions}).\n *\n * Need the raw bytes API or the Worker instance? Use `fs.backend` / `fs.worker`.\n * For the workerless async backend, use {@link createOPFSAsync}.\n */\nexport function createOPFSDedicated(options?: DedicatedWorkerOptions): OPFSFacade {\n const { fs, worker, dispose } = createDedicatedWorker(options);\n\n return new OPFSFacade({ fs, worker, dispose });\n}\n"],"names":["InlineWorker","WorkerCtor","applyWorkerOptions","fs","options","createDedicatedWorker","url","providedWorker","fsOptions","worker","wrap","createOPFSDedicated","dispose","OPFSFacade"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qdAOA,MAAMA,EAAeC,EA0BrB,SAASC,EAAmBC,EAAwCC,EAA6B,CACxFA,IAIDA,EAAQ,4BAA4B,mBACpCA,EAAQ,iBAAmBA,EAAQ,iBAAiB,MAGnDD,EAAG,WAAWC,CAAO,EAC9B,CAOO,SAASC,EAAsBD,EAAkC,GAAe,CACnF,KAAM,CAAE,IAAAE,EAAK,OAAQC,EAAgB,GAAGC,GAAcJ,EAEhDK,EAASF,IACTD,EAAM,IAAI,OAAOA,EAAK,CAAE,KAAM,QAAA,CAAU,EAAI,IAAIN,GAChDG,EAAKO,EAAAA,KAAqBD,CAAM,EAEtC,OAAAP,EAAmBC,EAAIK,CAAS,EAEzB,CACH,GAAAL,EACA,OAAAM,EACA,SAAU,EACA,SAAW,CACb,GAAI,CACA,MAAMN,EAAG,QAAA,CACb,QAAA,CAEIM,EAAO,UAAA,CACX,CACJ,GAAA,CACJ,CAAA,CAER,CCvDO,SAASE,EAAoBP,EAA8C,CAC9E,KAAM,CAAE,GAAAD,EAAI,OAAAM,EAAQ,QAAAG,CAAA,EAAYP,EAAsBD,CAAO,EAE7D,OAAO,IAAIS,EAAAA,WAAW,CAAE,GAAAV,EAAI,OAAAM,EAAQ,QAAAG,EAAS,CACjD"}
@@ -1,36 +0,0 @@
1
- # Backend API
2
-
3
- Classes from `opfs-worker/pure` (also re-exported from `/sync`, `/async`, `/sharedworker` where it makes sense). Bytes only — no encoding helpers.
4
-
5
- ```
6
- BaseOPFS mkdir, stat, readDir, watch, index, createIndex, …
7
- ├─ OPFSSync sync access handles + FDs + writeStream
8
- └─ OPFSAsync getFile / createWritable + writeStream (no FDs)
9
- ```
10
-
11
- `OPFSApi` = the `OPFSSync` method surface — both backends and Comlink proxies satisfy it.
12
-
13
- ## Shared methods (`BaseOPFS`)
14
-
15
- Path ops: `mkdir`, `stat`, `readDir`, `exists`, `clear`, `remove`, `rename`, `copy`, `realpath`, `index`, `createIndex`, `watch`, `unwatch`, `setOptions`, `dispose`.
16
-
17
- Subclasses implement:
18
-
19
- - `readFile` / `writeFile` / `appendFile`
20
- - `writeStream(path, stream, onProgress?)`
21
-
22
- ## `OPFSSync`
23
-
24
- Dedicated-worker backend. Adds FD methods (`open` … `fsync`) and streams via chunked FD writes.
25
-
26
- → [File descriptors](../file-descriptors.md), [dedicated guide](../guides/dedicated.md).
27
-
28
- ## `OPFSAsync`
29
-
30
- Promise File System API. Streams via `createWritable()`. FDs always throw `OperationNotSupportedError`. Writes need Safari 26+ (or Chrome / Firefox).
31
-
32
- → [Async guide](../guides/async.md).
33
-
34
- ## Comlink
35
-
36
- Dedicated and SharedWorker facades expose the same backend surface on `fs.backend` (a Comlink proxy). For FD `read`/`write` from the main thread, transfer buffers with Comlink — the facade does that for you.
@@ -1,82 +0,0 @@
1
- # Create helpers
2
-
3
- Factories from the package entries. For when to pick which: [Choosing a mode](../choosing-a-mode.md).
4
-
5
- ## Facade
6
-
7
- | Function | From | Backend |
8
- | ------------------------------- | ---------------------- | ----------------------------- |
9
- | `createOPFSDedicated(options?)` | `.` or `/sync` | Dedicated worker + `OPFSSync` |
10
- | `createOPFSAsync(options?)` | `.` or `/async` | In-process `OPFSAsync` |
11
- | `createOPFSShared(options?)` | `.` or `/sharedworker` | SharedWorker + `OPFSAsync` |
12
-
13
- All return [`OPFSFacade`](./facade.md).
14
-
15
- ```typescript
16
- import { createOPFSDedicated, createOPFSAsync, createOPFSShared } from 'opfs-worker';
17
- ```
18
-
19
- On the main entry only:
20
-
21
- - `createOPFS` → `createOPFSDedicated`
22
- - `createWorker` → same (deprecated)
23
- - `OPFSFileSystem` → `OPFSFacade` (deprecated)
24
-
25
- ## Escape hatch
26
-
27
- Every facade exposes:
28
-
29
- | Field | Meaning |
30
- | ------------ | --------------------------------------------------------------------- |
31
- | `fs.backend` | Raw [`OPFSApi`](../types.md#opfsapi) — bytes in / bytes out |
32
- | `fs.worker` | `Worker` / `SharedWorker` when one was created; `undefined` for async |
33
-
34
- ```typescript
35
- const fs = createOPFSDedicated({ root: '/my-app' });
36
- await fs.backend.writeFile('/a.bin', bytes);
37
- fs.worker; // Worker
38
- ```
39
-
40
- ## Options
41
-
42
- Passed to any `createOPFS*` (and to `setOptions()` later). Full type: [`OPFSOptions`](../types.md#opfsoptions).
43
-
44
- | Option | Default | What it does |
45
- | ------------------ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
46
- | `root` | `'/'` | Scope all paths under this OPFS subdirectory |
47
- | `namespace` | `'opfs-worker:${root}'` | Stamp on every [watch](../guides/watching.md) event |
48
- | `hashAlgorithm` | `'etag'` | File hash on `stat` / `index` / watch — `'etag'`, `'SHA-*'`, or `null`/`false` to disable. See [hashing](../guides/hashing.md) |
49
- | `maxFileSize` | `50MB` | Skip SHA-\* hashing above this size (`etag` ignores it) |
50
- | `broadcastChannel` | `'opfs-worker'` | Channel name, a `BroadcastChannel` instance, or `null` to disable |
51
-
52
- ### Dedicated worker only
53
-
54
- | Option | Type | Default | What it does |
55
- | -------- | --------------- | -------------- | ---------------------------------------------------------------------------------- |
56
- | `url` | `string \| URL` | inlined worker | Script URL for `opfs-worker/dedicated.worker.js` (or your own) instead of the blob |
57
- | `worker` | `Worker` | — | Pass an existing `Worker` (overrides `url`) |
58
-
59
- ### SharedWorker only
60
-
61
- | Option | Type | Default | What it does |
62
- | -------- | --------------- | ------------------- | ----------------------------------------------------------------------------------------------------- |
63
- | `url` | `string \| URL` | next to the package | Script URL for `opfs-worker/shared.worker.js` — with Vite: `import url from '…/shared.worker.js?url'` |
64
- | `worker` | `SharedWorker` | — | Pass an existing `SharedWorker` (overrides `url`) |
65
- | `name` | `string` | `'opfs-worker'` | Tabs with the same script URL + name share one instance |
66
-
67
- ```typescript
68
- const fs = createOPFS({
69
- root: '/my-app',
70
- hashAlgorithm: 'SHA-256',
71
- maxFileSize: 10 * 1024 * 1024,
72
- });
73
- ```
74
-
75
- ## Prebuilt scripts
76
-
77
- | Export | Hook up with |
78
- | --------------------------------- | -------------------------------------------------------- |
79
- | `opfs-worker/dedicated.worker.js` | `new Worker(url, { type: 'module' })` or `{ url }` |
80
- | `opfs-worker/shared.worker.js` | `new SharedWorker(url, { type: 'module' })` or `{ url }` |
81
-
82
- Walkthroughs: [dedicated](../guides/dedicated.md), [sharedworker](../guides/sharedworker.md).
@@ -1,52 +0,0 @@
1
- # OPFSFacade
2
-
3
- Node-ish API: encodings, auto-detect by extension, path as `string` or `URL`. You normally get one from [`createOPFS*`](./create.md); you can also `new OPFSFacade({ fs, worker?, dispose })`.
4
-
5
- `fs.promises === fs`.
6
-
7
- ## Escape hatch
8
-
9
- | Field | Notes |
10
- | ----- | ----- |
11
- | `backend` | Raw [`OPFSApi`](../types.md#opfsapi) — same methods without encoding helpers |
12
- | `worker` | `Worker` / `SharedWorker` if this facade owns one; `undefined` for async |
13
-
14
- ## File I/O
15
-
16
- | Method | Notes |
17
- | ------ | ----- |
18
- | `readFile` / `writeFile` / `appendFile` | Encoding as string, `{ encoding }`, or auto |
19
- | `importStream` | Stream / Blob / File — [streaming](../guides/streaming.md) |
20
- | `readText` / `writeText` / `appendText` | UTF-8 by default |
21
-
22
- ## Directories & metadata
23
-
24
- | Method | Notes |
25
- | ------ | ----- |
26
- | `mkdir` | `{ recursive }`; numeric mode is accepted and ignored |
27
- | `readDir` | `DirentData[]` |
28
- | `stat` / `exists` / `realpath` | |
29
- | `remove` | `{ recursive, force }` |
30
- | `rename` / `copy` | `copy` takes `{ recursive, overwrite }` |
31
- | `clear` | Empty a dir (default `/`) |
32
- | `index` | `Map<path, FileStat>` |
33
- | `createIndex` | Bulk `[path, string \| Uint8Array \| Blob][]` |
34
-
35
- ## Watch & lifecycle
36
-
37
- | Method | Notes |
38
- | ------ | ----- |
39
- | `watch` | Returns `() => void` |
40
- | `unwatch` | |
41
- | `setOptions` | [Hashing](../guides/hashing.md) and friends |
42
- | `dispose` | Tear down the backend |
43
-
44
- ## Node aliases
45
-
46
- `unlink` / `rm` / `rmdir` → `remove`. `readdir` → `readDir`. `lstat` → `stat`. `chmod` is a no-op (no Unix modes in OPFS).
47
-
48
- ## File descriptors
49
-
50
- `open`, `read`, `write`, `close`, `fstat`, `ftruncate`, `fsync` — dedicated / `OPFSSync` only. Async throws `ENOTSUP`.
51
-
52
- Full story: [file descriptors](../file-descriptors.md).
@@ -1,41 +0,0 @@
1
- # Choosing a mode
2
-
3
- Sync access handles only work in a **dedicated** worker. Async writes (`createWritable`) work on the main thread and in SharedWorkers too, but Safari needs **26+** for writing.
4
-
5
- ## Package entries
6
-
7
- | Entry | What you get |
8
- | --------------------------------- | --------------------------------------------------------------- |
9
- | `opfs-worker` | Everything (plus 1.x aliases) |
10
- | `opfs-worker/sync` | Dedicated worker only — `createOPFSDedicated`, `OPFSSync` |
11
- | `opfs-worker/async` | No worker — `createOPFSAsync`, `OPFSAsync` |
12
- | `opfs-worker/sharedworker` | SharedWorker helpers |
13
- | `opfs-worker/pure` | Classes only — you own the thread |
14
- | `opfs-worker/dedicated.worker.js` | Prebuilt dedicated Worker script |
15
- | `opfs-worker/shared.worker.js` | Prebuilt SharedWorker script |
16
-
17
- ## Modes
18
-
19
- | | API | Reach for it when… | FD | Comlink |
20
- | ----- | --------------------------------------------------------- | ------------------------------- | --------- | ------- |
21
- | **1** | [`createOPFSDedicated()`](./guides/dedicated.md) | You want a normal `fs`-like API | yes | yes |
22
- | **2** | [`OPFSSync` / `OPFSAsync` from `/pure`](./guides/pure.md) | You’re already in a worker | sync only | no |
23
- | **3** | [`createOPFSAsync()`](./guides/async.md) | You don’t want a worker at all | no | no |
24
- | **4** | [`createOPFSShared()`](./guides/sharedworker.md) | All tabs should share one fs | no | yes |
25
-
26
- Need the raw bytes API or the browser Worker? Use `fs.backend` / `fs.worker` on any facade — no separate factory.
27
-
28
- If size matters, import from `/sync`, `/async`, or `/sharedworker` instead of the main barrel.
29
-
30
- ## Trade-offs
31
-
32
- | | Dedicated (`OPFSSync`) | Async (`OPFSAsync`) |
33
- | ------------------------- | -------------------------------------------------------------------------------------- | ------------------------------ |
34
- | File descriptors | yes | `ENOTSUP` |
35
- | Safari writes | yes (via the worker) | 26+ |
36
- | SharedWorker | no | yes |
37
- | One instance for all tabs | no (unless you build SharedWorker yourself) | Mode 4 |
38
- | Bundle | ~80 KB inlined worker, or [prebuilt script](./guides/dedicated.md#diy-prebuilt-script) | small via `/async` |
39
- | CSP without `blob:` | pass `url` / prebuilt script | no worker, or SharedWorker URL |
40
-
41
- Aliases on the main entry: `createOPFS` / `createWorker` → `createOPFSDedicated`, `OPFSFileSystem` → `OPFSFacade`. See [Migration](./migration.md).