opfs-worker 1.3.2 → 2.1.0
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 +64 -458
- package/dist/BaseOPFS-BPw9AIQ-.cjs +4 -0
- package/dist/BaseOPFS-BPw9AIQ-.cjs.map +1 -0
- package/dist/BaseOPFS-Cylz6ijk.js +2036 -0
- package/dist/BaseOPFS-Cylz6ijk.js.map +1 -0
- package/dist/OPFSAsync-BKSAJJeh.js +124 -0
- package/dist/OPFSAsync-BKSAJJeh.js.map +1 -0
- package/dist/OPFSAsync-s2P7y3sw.cjs +2 -0
- package/dist/OPFSAsync-s2P7y3sw.cjs.map +1 -0
- package/dist/OPFSFacade-DePnNRgt.cjs +2 -0
- package/dist/OPFSFacade-DePnNRgt.cjs.map +1 -0
- package/dist/OPFSFacade-XohWlHuu.js +281 -0
- package/dist/OPFSFacade-XohWlHuu.js.map +1 -0
- package/dist/OPFSSync-C7KBepe_.cjs +2 -0
- package/dist/OPFSSync-C7KBepe_.cjs.map +1 -0
- package/dist/OPFSSync-CsSQkpk5.js +208 -0
- package/dist/OPFSSync-CsSQkpk5.js.map +1 -0
- package/dist/assets/dedicated.worker-nY3tK4zi.js.map +1 -0
- package/dist/{worker.d.ts → core/BaseOPFS.d.ts} +34 -300
- package/dist/core/BaseOPFS.d.ts.map +1 -0
- package/dist/core/OPFSAsync.d.ts +55 -0
- package/dist/core/OPFSAsync.d.ts.map +1 -0
- package/dist/core/OPFSSync.d.ts +54 -0
- package/dist/core/OPFSSync.d.ts.map +1 -0
- package/dist/createOPFSAsync-BwKDmHsy.cjs +2 -0
- package/dist/createOPFSAsync-BwKDmHsy.cjs.map +1 -0
- package/dist/createOPFSAsync-Y4Mg6qte.js +10 -0
- package/dist/createOPFSAsync-Y4Mg6qte.js.map +1 -0
- package/dist/createOPFSDedicated-CsnV6MLP.js +2333 -0
- package/dist/createOPFSDedicated-CsnV6MLP.js.map +1 -0
- package/dist/createOPFSDedicated-pKTRWLdz.cjs +2283 -0
- package/dist/createOPFSDedicated-pKTRWLdz.cjs.map +1 -0
- package/dist/createOPFSShared-CGdd__PH.js +23 -0
- package/dist/createOPFSShared-CGdd__PH.js.map +1 -0
- package/dist/createOPFSShared-CskROt7U.cjs +2 -0
- package/dist/createOPFSShared-CskROt7U.cjs.map +1 -0
- package/dist/dedicated.worker.js +2281 -0
- package/dist/dedicated.worker.js.map +1 -0
- package/dist/{facade.d.ts → facade/OPFSFacade.d.ts} +35 -10
- package/dist/facade/OPFSFacade.d.ts.map +1 -0
- package/dist/facade/createOPFSAsync.d.ts +16 -0
- package/dist/facade/createOPFSAsync.d.ts.map +1 -0
- package/dist/facade/createOPFSDedicated.d.ts +17 -0
- package/dist/facade/createOPFSDedicated.d.ts.map +1 -0
- package/dist/facade/createOPFSShared.d.ts +24 -0
- package/dist/facade/createOPFSShared.d.ts.map +1 -0
- package/dist/index.async.cjs +2 -0
- package/dist/index.async.cjs.map +1 -0
- package/dist/index.async.d.ts +10 -0
- package/dist/index.async.d.ts.map +1 -0
- package/dist/index.async.js +55 -0
- package/dist/index.async.js.map +1 -0
- package/dist/index.cjs +1 -2466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -2799
- package/dist/index.js.map +1 -1
- package/dist/index.pure.cjs +2 -0
- package/dist/index.pure.cjs.map +1 -0
- package/dist/index.pure.d.ts +8 -0
- package/dist/index.pure.d.ts.map +1 -0
- package/dist/index.pure.js +53 -0
- package/dist/index.pure.js.map +1 -0
- package/dist/index.sharedworker.cjs +2 -0
- package/dist/index.sharedworker.cjs.map +1 -0
- package/dist/index.sharedworker.d.ts +11 -0
- package/dist/index.sharedworker.d.ts.map +1 -0
- package/dist/index.sharedworker.js +55 -0
- package/dist/index.sharedworker.js.map +1 -0
- package/dist/index.sync.cjs +2 -0
- package/dist/index.sync.cjs.map +1 -0
- package/dist/index.sync.d.ts +11 -0
- package/dist/index.sync.d.ts.map +1 -0
- package/dist/index.sync.js +55 -0
- package/dist/index.sync.js.map +1 -0
- package/dist/shared.worker.js +2166 -0
- package/dist/shared.worker.js.map +1 -0
- package/dist/types.d.ts +9 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +11 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker/createDedicatedWorker.d.ts +30 -0
- package/dist/worker/createDedicatedWorker.d.ts.map +1 -0
- package/dist/worker/createSharedWorker.d.ts +37 -0
- package/dist/worker/createSharedWorker.d.ts.map +1 -0
- package/dist/worker/dedicated.worker.d.ts +2 -0
- package/dist/worker/dedicated.worker.d.ts.map +1 -0
- package/dist/worker/shared.worker.d.ts +2 -0
- package/dist/worker/shared.worker.d.ts.map +1 -0
- package/docs/README.md +30 -0
- package/docs/api/backend.md +36 -0
- package/docs/api/create.md +82 -0
- package/docs/api/facade.md +52 -0
- package/docs/choosing-a-mode.md +41 -0
- package/docs/file-descriptors.md +695 -0
- package/docs/guides/async.md +36 -0
- package/docs/guides/dedicated.md +76 -0
- package/docs/guides/hashing.md +34 -0
- package/docs/guides/pure.md +46 -0
- package/docs/guides/sharedworker.md +57 -0
- package/docs/guides/streaming.md +51 -0
- package/docs/guides/watching.md +35 -0
- package/docs/migration.md +41 -0
- package/docs/types.md +246 -0
- package/package.json +55 -10
- package/src/core/BaseOPFS.ts +951 -0
- package/src/core/OPFSAsync.ts +248 -0
- package/src/core/OPFSSync.ts +460 -0
- package/src/facade/OPFSFacade.ts +489 -0
- package/src/facade/createOPFSAsync.ts +22 -0
- package/src/facade/createOPFSDedicated.ts +23 -0
- package/src/facade/createOPFSShared.ts +30 -0
- package/src/index.async.ts +11 -0
- package/src/index.pure.ts +8 -0
- package/src/index.sharedworker.ts +12 -0
- package/src/index.sync.ts +12 -0
- package/src/index.ts +44 -0
- package/src/types.ts +103 -0
- package/src/utils/encoder.ts +205 -0
- package/src/utils/errors.ts +297 -0
- package/src/utils/helpers.ts +465 -0
- package/src/worker/createDedicatedWorker.ts +74 -0
- package/src/worker/createSharedWorker.ts +67 -0
- package/src/worker/dedicated.worker.ts +13 -0
- package/src/worker/shared.worker.ts +17 -0
- package/dist/assets/worker-1Wh1cr7P.js.map +0 -1
- package/dist/assets/worker-BeJaVyBV.js.map +0 -1
- package/dist/assets/worker-DYYLzR1Y.js.map +0 -1
- package/dist/facade.d.ts.map +0 -1
- package/dist/helpers-BuGfPAg0.js +0 -1439
- package/dist/helpers-BuGfPAg0.js.map +0 -1
- package/dist/helpers-CF7A2WQG.cjs +0 -4
- package/dist/helpers-CF7A2WQG.cjs.map +0 -1
- package/dist/helpers-CIiblZ8d.cjs +0 -4
- package/dist/helpers-CIiblZ8d.cjs.map +0 -1
- package/dist/helpers-CKOebsbw.js +0 -1423
- package/dist/helpers-CKOebsbw.js.map +0 -1
- package/dist/helpers-Ca2c767K.js +0 -1427
- package/dist/helpers-Ca2c767K.js.map +0 -1
- package/dist/helpers-Dwc92hv9.cjs +0 -4
- package/dist/helpers-Dwc92hv9.cjs.map +0 -1
- package/dist/raw.cjs +0 -2
- package/dist/raw.cjs.map +0 -1
- package/dist/raw.d.ts +0 -13
- package/dist/raw.d.ts.map +0 -1
- package/dist/raw.js +0 -1001
- package/dist/raw.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Remote } from 'comlink';
|
|
1
|
+
import type { OPFSSync } from './core/OPFSSync';
|
|
3
2
|
/**
|
|
4
3
|
* Type for paths that can be either a string or URI
|
|
5
4
|
*/
|
|
@@ -37,8 +36,14 @@ export interface WatchEvent {
|
|
|
37
36
|
timestamp: string;
|
|
38
37
|
hash?: string;
|
|
39
38
|
}
|
|
40
|
-
export type {
|
|
41
|
-
|
|
39
|
+
export type { OPFSSync };
|
|
40
|
+
/**
|
|
41
|
+
* Promise-based fs API surface shared by all backends: a Comlink proxy to
|
|
42
|
+
* `OPFSSync` in a worker, or an in-process `OPFSAsync` instance.
|
|
43
|
+
*/
|
|
44
|
+
export type OPFSApi = {
|
|
45
|
+
[K in keyof OPFSSync]: OPFSSync[K];
|
|
46
|
+
};
|
|
42
47
|
export interface OPFSOptions {
|
|
43
48
|
/** Root path for the file system (default: '/') */
|
|
44
49
|
root?: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,GAAG,CAAC;AAEpC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,WAAW,CAAC;AAExC,MAAM,MAAM,cAAc,GAAG,OAAO,GAChC,MAAM,GACN,OAAO,GACP,SAAS,GACT,UAAU,GACV,MAAM,GACN,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,KAAK,CAAC;AAEV,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEtC,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,cAAc,CAAC;AAEvD,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,MAAM,EA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E,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB"}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -5,7 +5,17 @@ import type { Encoding } from '../types';
|
|
|
5
5
|
* @throws {OPFSNotSupportedError} If the browser does not support the OPFS API
|
|
6
6
|
*/
|
|
7
7
|
export declare function checkOPFSSupport(): void;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Run a callback while holding an exclusive lock on a path
|
|
10
|
+
*
|
|
11
|
+
* Locks are always exclusive: OPFS permits a single sync access handle per file,
|
|
12
|
+
* so readers can't share access either.
|
|
13
|
+
*
|
|
14
|
+
* @param path - The path to lock
|
|
15
|
+
* @param fn - The callback to run while holding the lock
|
|
16
|
+
* @returns The value returned by the callback
|
|
17
|
+
*/
|
|
18
|
+
export declare function withLock<T>(path: string, fn: () => Promise<T>): Promise<T>;
|
|
9
19
|
/**
|
|
10
20
|
* Split a path into an array of segments
|
|
11
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAIvC;AAED,wBAAsB,QAAQ,CAAC,CAAC,EAC5B,IAAI,EAAE,MAAM,EACZ,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC;;;;GAIG;AACH,wBAAgB,gBAAgB,IA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oBAAoB,EAChC,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,0BAA0B,CAAC,CAOrC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { OPFSOptions, OPFSSync } from '../types';
|
|
2
|
+
import type { Remote } from 'comlink';
|
|
3
|
+
type RemoteOPFSSync = Remote<OPFSSync>;
|
|
4
|
+
export interface DedicatedWorkerOptions extends OPFSOptions {
|
|
5
|
+
/**
|
|
6
|
+
* URL of the worker script, e.g. `import url from 'opfs-worker/dedicated.worker.js?url'` (Vite).
|
|
7
|
+
*
|
|
8
|
+
* Defaults to the inlined worker (no URL needed). Pass an explicit url when you
|
|
9
|
+
* prefer the self-contained file (strict CSP without `blob:`, or DIY hosting).
|
|
10
|
+
*/
|
|
11
|
+
url?: string | URL;
|
|
12
|
+
/** Bring your own Worker instance (overrides `url`) */
|
|
13
|
+
worker?: Worker;
|
|
14
|
+
}
|
|
15
|
+
export interface RawWorker {
|
|
16
|
+
/** Comlink proxy to `OPFSSync` (bytes in / bytes out) */
|
|
17
|
+
fs: RemoteOPFSSync;
|
|
18
|
+
/** Underlying browser Worker */
|
|
19
|
+
worker: Worker;
|
|
20
|
+
/** Calls worker `dispose()` then `terminate()` */
|
|
21
|
+
dispose: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Internal helper: spawn a dedicated worker and wrap `OPFSSync` with Comlink.
|
|
25
|
+
* Prefer {@link createOPFSDedicated}; access the proxy / Worker via
|
|
26
|
+
* `facade.backend` / `facade.worker`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createDedicatedWorker(options?: DedicatedWorkerOptions): RawWorker;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=createDedicatedWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDedicatedWorker.d.ts","sourceRoot":"","sources":["../../src/worker/createDedicatedWorker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAItC,KAAK,cAAc,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEvC,MAAM,WAAW,sBAAuB,SAAQ,WAAW;IACvD;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACtB,yDAAyD;IACzD,EAAE,EAAE,cAAc,CAAC;IACnB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB;AAeD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,SAAS,CAuBrF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { OPFSAsync } from '../core/OPFSAsync';
|
|
2
|
+
import type { OPFSOptions } from '../types';
|
|
3
|
+
import type { Remote } from 'comlink';
|
|
4
|
+
type RemoteOPFSAsync = Remote<OPFSAsync>;
|
|
5
|
+
export interface SharedWorkerOptions extends OPFSOptions {
|
|
6
|
+
/**
|
|
7
|
+
* URL of the worker script, e.g. `import url from 'opfs-worker/shared.worker.js?url'` (Vite).
|
|
8
|
+
*
|
|
9
|
+
* Defaults to `new URL('./shared.worker.js', import.meta.url)`, which works when
|
|
10
|
+
* `opfs-worker` is served as-is (CDN, unbundled deps). When your bundler inlines
|
|
11
|
+
* the package into app chunks, pass the url explicitly.
|
|
12
|
+
*/
|
|
13
|
+
url?: string | URL;
|
|
14
|
+
/** Bring your own SharedWorker instance (overrides `url`) */
|
|
15
|
+
worker?: SharedWorker;
|
|
16
|
+
/** Worker name — tabs with the same script URL + name share one instance (default: 'opfs-worker') */
|
|
17
|
+
name?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RawSharedWorker {
|
|
20
|
+
/** Comlink proxy to the `OPFSAsync` instance shared by all connected tabs */
|
|
21
|
+
fs: RemoteOPFSAsync;
|
|
22
|
+
/** Underlying browser SharedWorker */
|
|
23
|
+
worker: SharedWorker;
|
|
24
|
+
/** Closes this tab's port; the worker keeps running for other tabs */
|
|
25
|
+
dispose: () => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Internal helper: connect to the SharedWorker and wrap `OPFSAsync` with Comlink.
|
|
29
|
+
* Prefer {@link createOPFSShared}; access the proxy / SharedWorker via
|
|
30
|
+
* `facade.backend` / `facade.worker`.
|
|
31
|
+
*
|
|
32
|
+
* Note: `OPFSOptions` are applied via `setOptions()` on the shared instance, so
|
|
33
|
+
* they affect every connected tab — use the same options in all tabs.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createSharedWorker(options?: SharedWorkerOptions): RawSharedWorker;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=createSharedWorker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSharedWorker.d.ts","sourceRoot":"","sources":["../../src/worker/createSharedWorker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,KAAK,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AAEzC,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACpD;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,qGAAqG;IACrG,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC5B,6EAA6E;IAC7E,EAAE,EAAE,eAAe,CAAC;IACpB,sCAAsC;IACtC,MAAM,EAAE,YAAY,CAAC;IACrB,sEAAsE;IACtE,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,mBAAwB,GAAG,eAAe,CA0BrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedicated.worker.d.ts","sourceRoot":"","sources":["../../src/worker/dedicated.worker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.worker.d.ts","sourceRoot":"","sources":["../../src/worker/shared.worker.ts"],"names":[],"mappings":""}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Docs
|
|
2
|
+
|
|
3
|
+
New here? Start with [Choosing a mode](./choosing-a-mode.md).
|
|
4
|
+
|
|
5
|
+
## Guides
|
|
6
|
+
|
|
7
|
+
| Guide | About |
|
|
8
|
+
| ----------------------------------------- | -------------------------------------------------- |
|
|
9
|
+
| [Choosing a mode](./choosing-a-mode.md) | Which entry / backend to pick |
|
|
10
|
+
| [Dedicated worker](./guides/dedicated.md) | Default path + DIY worker script |
|
|
11
|
+
| [Async (no worker)](./guides/async.md) | `createOPFSAsync` on the current thread |
|
|
12
|
+
| [SharedWorker](./guides/sharedworker.md) | One fs shared by all tabs |
|
|
13
|
+
| [Pure classes](./guides/pure.md) | Drop `OPFSSync` / `OPFSAsync` into your own worker |
|
|
14
|
+
| [Streaming](./guides/streaming.md) | Large files with `importStream` |
|
|
15
|
+
| [Watching](./guides/watching.md) | Change events over `BroadcastChannel` |
|
|
16
|
+
| [Hashing](./guides/hashing.md) | etag vs SHA |
|
|
17
|
+
|
|
18
|
+
## API
|
|
19
|
+
|
|
20
|
+
| Page | About |
|
|
21
|
+
| ----------------------------------------- | ------------------------------------- |
|
|
22
|
+
| [Create helpers](./api/create.md) | `createOPFS*` + **options table** |
|
|
23
|
+
| [Facade](./api/facade.md) | Node-like methods and aliases |
|
|
24
|
+
| [Backend](./api/backend.md) | `BaseOPFS` / `OPFSSync` / `OPFSAsync` |
|
|
25
|
+
| [File descriptors](./file-descriptors.md) | `open` / `read` / `write` / … |
|
|
26
|
+
| [Types](./types.md) | Types and errors |
|
|
27
|
+
|
|
28
|
+
## Migration
|
|
29
|
+
|
|
30
|
+
[1.x → 2.x](./migration.md)
|
|
@@ -0,0 +1,36 @@
|
|
|
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.
|
|
@@ -0,0 +1,82 @@
|
|
|
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).
|
|
@@ -0,0 +1,52 @@
|
|
|
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).
|
|
@@ -0,0 +1,41 @@
|
|
|
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).
|