opfs-worker 1.3.0 → 1.3.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/dist/assets/worker-BeJaVyBV.js.map +1 -0
- package/dist/assets/worker-DYYLzR1Y.js.map +1 -0
- package/dist/facade.d.ts +4 -4
- package/dist/facade.d.ts.map +1 -1
- package/dist/helpers-CIiblZ8d.cjs +4 -0
- package/dist/helpers-CIiblZ8d.cjs.map +1 -0
- package/dist/helpers-CKOebsbw.js +1423 -0
- package/dist/helpers-CKOebsbw.js.map +1 -0
- package/dist/helpers-Ca2c767K.js +1427 -0
- package/dist/helpers-Ca2c767K.js.map +1 -0
- package/dist/helpers-Dwc92hv9.cjs +4 -0
- package/dist/helpers-Dwc92hv9.cjs.map +1 -0
- package/dist/index.cjs +183 -178
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +228 -217
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +51 -46
- package/dist/raw.js.map +1 -1
- package/dist/utils/errors.d.ts +16 -20
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +4 -2
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +1 -5
- package/dist/worker.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/raw.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { expose as
|
|
2
|
-
import { V as E,
|
|
1
|
+
import { expose as O, transfer as p } from "comlink";
|
|
2
|
+
import { V as E, t as D, l as k, h as z, q as F, s as v, P, w as u, E as m, m as l, n as M, j as x, W as h, o as b, p as S, z as T, O as f, D as $, G as _, v as H, A as C, c as N, g as R, r as B, L as U, J as A, H as I, K as W, k as g, C as L } from "./helpers-Ca2c767K.js";
|
|
3
3
|
class j {
|
|
4
4
|
/** Root directory handle for the file system */
|
|
5
5
|
root;
|
|
@@ -37,8 +37,7 @@ class j {
|
|
|
37
37
|
* This method is called by internal operations to notify clients about
|
|
38
38
|
* changes, even when no specific paths are being watched.
|
|
39
39
|
*
|
|
40
|
-
* @param
|
|
41
|
-
* @param type - The type of change (create, change, delete)
|
|
40
|
+
* @param event - The event describing the change
|
|
42
41
|
*/
|
|
43
42
|
async notifyChange(t) {
|
|
44
43
|
if (!this.options.broadcastChannel)
|
|
@@ -76,7 +75,7 @@ class j {
|
|
|
76
75
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
77
76
|
*/
|
|
78
77
|
constructor(t) {
|
|
79
|
-
|
|
78
|
+
k(), t && this.setOptions(t);
|
|
80
79
|
}
|
|
81
80
|
/**
|
|
82
81
|
* Initialize the file system within a given directory
|
|
@@ -84,7 +83,6 @@ class j {
|
|
|
84
83
|
* This method sets up the root directory for all subsequent operations.
|
|
85
84
|
* If no root is specified, it will use the OPFS root directory.
|
|
86
85
|
*
|
|
87
|
-
* @param root - The root path for the file system (default: '/')
|
|
88
86
|
* @returns Promise that resolves to true if initialization was successful
|
|
89
87
|
* @throws {OPFSError} If initialization fails
|
|
90
88
|
*
|
|
@@ -106,7 +104,7 @@ class j {
|
|
|
106
104
|
const i = await navigator.storage.getDirectory();
|
|
107
105
|
this.root = t === "/" ? i : await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
108
106
|
} catch (i) {
|
|
109
|
-
a(new
|
|
107
|
+
a(new z(t, i));
|
|
110
108
|
} finally {
|
|
111
109
|
this.mountingPromise = null;
|
|
112
110
|
}
|
|
@@ -144,7 +142,7 @@ class j {
|
|
|
144
142
|
* ```
|
|
145
143
|
*/
|
|
146
144
|
async getDirectoryHandle(t, e = !1, a = this.root) {
|
|
147
|
-
const i = Array.isArray(t) ? t :
|
|
145
|
+
const i = Array.isArray(t) ? t : v(t);
|
|
148
146
|
let r = a;
|
|
149
147
|
for (const s of i)
|
|
150
148
|
r = await r.getDirectoryHandle(s, { create: e });
|
|
@@ -170,9 +168,9 @@ class j {
|
|
|
170
168
|
* ```
|
|
171
169
|
*/
|
|
172
170
|
async getFileHandle(t, e = !1, a = this.root) {
|
|
173
|
-
const i =
|
|
171
|
+
const i = v(t);
|
|
174
172
|
if (i.length === 0)
|
|
175
|
-
throw new
|
|
173
|
+
throw new P("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
176
174
|
const r = i.pop();
|
|
177
175
|
return (await this.getDirectoryHandle(i, e, a)).getFileHandle(r, { create: e });
|
|
178
176
|
}
|
|
@@ -239,7 +237,7 @@ class j {
|
|
|
239
237
|
async readFile(t) {
|
|
240
238
|
await this.mount();
|
|
241
239
|
try {
|
|
242
|
-
return await
|
|
240
|
+
return await u(t, "shared", async () => {
|
|
243
241
|
const e = await this.open(t);
|
|
244
242
|
try {
|
|
245
243
|
const { size: a } = await this.fstat(e), i = new Uint8Array(a);
|
|
@@ -249,7 +247,7 @@ class j {
|
|
|
249
247
|
}
|
|
250
248
|
});
|
|
251
249
|
} catch (e) {
|
|
252
|
-
throw new
|
|
250
|
+
throw new m("file", t, e);
|
|
253
251
|
}
|
|
254
252
|
}
|
|
255
253
|
/**
|
|
@@ -277,7 +275,7 @@ class j {
|
|
|
277
275
|
async writeFile(t, e) {
|
|
278
276
|
await this.mount();
|
|
279
277
|
const a = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
280
|
-
await
|
|
278
|
+
await u(t, "exclusive", async () => {
|
|
281
279
|
const i = await this.exists(t), r = await this.open(t, { create: !0, truncate: !0 });
|
|
282
280
|
try {
|
|
283
281
|
await this.write(r, a, 0, a.length, null, !1), await this.fsync(r);
|
|
@@ -312,7 +310,7 @@ class j {
|
|
|
312
310
|
async appendFile(t, e) {
|
|
313
311
|
await this.mount();
|
|
314
312
|
const a = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
315
|
-
await
|
|
313
|
+
await u(t, "exclusive", async () => {
|
|
316
314
|
const i = await this.open(t, { create: !0 });
|
|
317
315
|
try {
|
|
318
316
|
const { size: r } = await this.fstat(i);
|
|
@@ -346,14 +344,17 @@ class j {
|
|
|
346
344
|
*/
|
|
347
345
|
async mkdir(t, e) {
|
|
348
346
|
await this.mount();
|
|
349
|
-
const a = e?.recursive ?? !1, i =
|
|
347
|
+
const a = e?.recursive ?? !1, i = v(t);
|
|
350
348
|
let r = this.root;
|
|
351
349
|
for (let s = 0; s < i.length; s++) {
|
|
352
350
|
const n = i[s];
|
|
353
351
|
try {
|
|
354
352
|
r = await r.getDirectoryHandle(n, { create: a || s === i.length - 1 });
|
|
355
353
|
} catch (o) {
|
|
356
|
-
throw o.name === "NotFoundError" ?
|
|
354
|
+
throw o.name === "NotFoundError" ? l(o, {
|
|
355
|
+
path: M(i.slice(0, s + 1)),
|
|
356
|
+
existenceType: "directory"
|
|
357
|
+
}) : o.name === "TypeMismatchError" ? l(o, { path: n, isDirectory: !1 }) : new x("create directory", n, o);
|
|
357
358
|
}
|
|
358
359
|
}
|
|
359
360
|
await this.notifyChange({ path: t, type: h.Added, isDirectory: !0 });
|
|
@@ -390,10 +391,10 @@ class j {
|
|
|
390
391
|
isFile: !1,
|
|
391
392
|
isDirectory: !0
|
|
392
393
|
};
|
|
393
|
-
const e =
|
|
394
|
+
const e = b(t);
|
|
394
395
|
let a;
|
|
395
396
|
try {
|
|
396
|
-
a = await this.getDirectoryHandle(
|
|
397
|
+
a = await this.getDirectoryHandle(S(t), !1);
|
|
397
398
|
const i = this.options.hashAlgorithm, s = await (await a.getFileHandle(e, { create: !1 })).getFile(), n = {
|
|
398
399
|
kind: "file",
|
|
399
400
|
size: s.size,
|
|
@@ -414,9 +415,9 @@ class j {
|
|
|
414
415
|
return n;
|
|
415
416
|
} catch (i) {
|
|
416
417
|
if (i.name === "NotFoundError")
|
|
417
|
-
throw new
|
|
418
|
+
throw new m("file", t, i);
|
|
418
419
|
if (i.name !== "TypeMismatchError")
|
|
419
|
-
throw new
|
|
420
|
+
throw new x("stat", t, i);
|
|
420
421
|
}
|
|
421
422
|
try {
|
|
422
423
|
return await a.getDirectoryHandle(e, { create: !1 }), {
|
|
@@ -428,7 +429,7 @@ class j {
|
|
|
428
429
|
isDirectory: !0
|
|
429
430
|
};
|
|
430
431
|
} catch (i) {
|
|
431
|
-
throw new
|
|
432
|
+
throw new x("stat", t, i);
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
435
|
/**
|
|
@@ -480,10 +481,10 @@ class j {
|
|
|
480
481
|
async exists(t) {
|
|
481
482
|
if (await this.mount(), t === "/")
|
|
482
483
|
return !0;
|
|
483
|
-
const e =
|
|
484
|
+
const e = b(t);
|
|
484
485
|
let a = null;
|
|
485
486
|
try {
|
|
486
|
-
a = await this.getDirectoryHandle(
|
|
487
|
+
a = await this.getDirectoryHandle(S(t), !1);
|
|
487
488
|
} catch (i) {
|
|
488
489
|
if (a = null, i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
489
490
|
throw i;
|
|
@@ -562,9 +563,9 @@ class j {
|
|
|
562
563
|
*/
|
|
563
564
|
async remove(t, e) {
|
|
564
565
|
if (await this.mount(), t === "/")
|
|
565
|
-
throw new
|
|
566
|
-
const { recursive: a = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(
|
|
567
|
-
await
|
|
566
|
+
throw new $("EROOT", t);
|
|
567
|
+
const { recursive: a = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(S(t), !1), s = await this.stat(t);
|
|
568
|
+
await _(r, t, { recursive: a, force: i }), await this.notifyChange({ path: t, type: h.Removed, isDirectory: s.isDirectory });
|
|
568
569
|
}
|
|
569
570
|
/**
|
|
570
571
|
* Resolve a path to an absolute path
|
|
@@ -587,9 +588,9 @@ class j {
|
|
|
587
588
|
async realpath(t) {
|
|
588
589
|
await this.mount();
|
|
589
590
|
try {
|
|
590
|
-
const e =
|
|
591
|
+
const e = H(t);
|
|
591
592
|
if (!await this.exists(e))
|
|
592
|
-
throw new
|
|
593
|
+
throw new m("file", e);
|
|
593
594
|
return e;
|
|
594
595
|
} catch (e) {
|
|
595
596
|
throw e instanceof f ? e : l(e, { path: t });
|
|
@@ -658,7 +659,7 @@ class j {
|
|
|
658
659
|
try {
|
|
659
660
|
const i = a?.recursive ?? !1, r = a?.overwrite ?? !0;
|
|
660
661
|
if (!await this.exists(t))
|
|
661
|
-
throw new
|
|
662
|
+
throw new m("source", t);
|
|
662
663
|
if (await this.exists(e) && !r)
|
|
663
664
|
throw new C(e);
|
|
664
665
|
if ((await this.stat(t)).isFile) {
|
|
@@ -666,12 +667,12 @@ class j {
|
|
|
666
667
|
await this.writeFile(e, c);
|
|
667
668
|
} else {
|
|
668
669
|
if (!i)
|
|
669
|
-
throw new
|
|
670
|
+
throw new N("directory", t);
|
|
670
671
|
await this.mkdir(e, { recursive: !0 });
|
|
671
672
|
const c = await this.readDir(t);
|
|
672
673
|
for (const w of c) {
|
|
673
|
-
const y = `${t}/${w.name}`,
|
|
674
|
-
await this.copy(y,
|
|
674
|
+
const y = `${t}/${w.name}`, d = `${e}/${w.name}`;
|
|
675
|
+
await this.copy(y, d, { recursive: !0, overwrite: r });
|
|
675
676
|
}
|
|
676
677
|
}
|
|
677
678
|
} catch (i) {
|
|
@@ -705,9 +706,9 @@ class j {
|
|
|
705
706
|
*/
|
|
706
707
|
async watch(t, e) {
|
|
707
708
|
if (!this.options.broadcastChannel)
|
|
708
|
-
throw new
|
|
709
|
+
throw new R("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
|
|
709
710
|
const a = {
|
|
710
|
-
pattern:
|
|
711
|
+
pattern: B(t, e?.recursive ?? !0),
|
|
711
712
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
712
713
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
713
714
|
};
|
|
@@ -748,15 +749,21 @@ class j {
|
|
|
748
749
|
*/
|
|
749
750
|
async open(t, e) {
|
|
750
751
|
await this.mount();
|
|
751
|
-
const { create: a = !1, exclusive: i = !1, truncate: r = !1 } = e || {}, s = F(
|
|
752
|
+
const { create: a = !1, exclusive: i = !1, truncate: r = !1 } = e || {}, s = F(H(t));
|
|
752
753
|
try {
|
|
753
|
-
return a && i ? await
|
|
754
|
+
return a && i ? await u(s, "exclusive", async () => {
|
|
754
755
|
if (await this.exists(s))
|
|
755
756
|
throw new C(s);
|
|
756
757
|
return this._openFile(s, a, r);
|
|
757
758
|
}) : await this._openFile(s, a, r);
|
|
758
759
|
} catch (n) {
|
|
759
|
-
|
|
760
|
+
if (n instanceof f)
|
|
761
|
+
throw n;
|
|
762
|
+
const o = n && n.name === "TypeMismatchError";
|
|
763
|
+
throw l(n, {
|
|
764
|
+
path: s,
|
|
765
|
+
isDirectory: !!o
|
|
766
|
+
});
|
|
760
767
|
}
|
|
761
768
|
}
|
|
762
769
|
/**
|
|
@@ -796,7 +803,7 @@ class j {
|
|
|
796
803
|
*/
|
|
797
804
|
async close(t) {
|
|
798
805
|
const e = this._getFileDescriptor(t);
|
|
799
|
-
|
|
806
|
+
A(t, e.syncHandle, e.path), this.openFiles.delete(t);
|
|
800
807
|
}
|
|
801
808
|
/**
|
|
802
809
|
* Read data from a file descriptor
|
|
@@ -824,13 +831,13 @@ class j {
|
|
|
824
831
|
*/
|
|
825
832
|
async read(t, e, a, i, r) {
|
|
826
833
|
const s = this._getFileDescriptor(t);
|
|
827
|
-
|
|
834
|
+
I(e.length, a, i, r);
|
|
828
835
|
try {
|
|
829
836
|
const n = r ?? s.position, o = s.syncHandle.getSize(), { isEOF: c, actualLength: w } = W(n, i, o);
|
|
830
837
|
if (c)
|
|
831
838
|
return p({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
832
|
-
const y = e.subarray(a, a + w),
|
|
833
|
-
return r == null && (s.position = n +
|
|
839
|
+
const y = e.subarray(a, a + w), d = s.syncHandle.read(y, { at: n });
|
|
840
|
+
return r == null && (s.position = n + d), p({ bytesRead: d, buffer: e }, [e.buffer]);
|
|
834
841
|
} catch (n) {
|
|
835
842
|
throw g("read", t, s.path, n);
|
|
836
843
|
}
|
|
@@ -858,7 +865,7 @@ class j {
|
|
|
858
865
|
*/
|
|
859
866
|
async write(t, e, a = 0, i, r, s = !0) {
|
|
860
867
|
const n = this._getFileDescriptor(t), o = i ?? e.length - a;
|
|
861
|
-
|
|
868
|
+
I(e.length, a, o, r);
|
|
862
869
|
try {
|
|
863
870
|
const c = r ?? n.position, w = e.subarray(a, a + o), y = n.syncHandle.write(w, { at: c });
|
|
864
871
|
return (r == null || r === n.position) && (n.position = c + y), s && await this.notifyChange({ path: n.path, type: h.Changed, isDirectory: !1 }), y;
|
|
@@ -945,7 +952,7 @@ class j {
|
|
|
945
952
|
dispose() {
|
|
946
953
|
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
947
954
|
for (const [t, e] of this.openFiles)
|
|
948
|
-
|
|
955
|
+
A(t, e.syncHandle, e.path);
|
|
949
956
|
this.openFiles.clear(), this.nextFd = 1;
|
|
950
957
|
}
|
|
951
958
|
/**
|
|
@@ -955,8 +962,6 @@ class j {
|
|
|
955
962
|
* This is useful for importing data from external sources or syncing with remote data.
|
|
956
963
|
*
|
|
957
964
|
* @param entries - Array of [path, data] tuples to sync
|
|
958
|
-
* @param options - Options for synchronization
|
|
959
|
-
* @param options.cleanBefore - Whether to clear the file system before syncing (default: false)
|
|
960
965
|
* @returns Promise that resolves when synchronization is complete
|
|
961
966
|
* @throws {OPFSError} If the synchronization fails
|
|
962
967
|
*
|
|
@@ -989,7 +994,7 @@ class j {
|
|
|
989
994
|
}
|
|
990
995
|
}
|
|
991
996
|
}
|
|
992
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
997
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && O(new j());
|
|
993
998
|
export {
|
|
994
999
|
j as OPFSWorker
|
|
995
1000
|
};
|