opfs-worker 0.2.5 → 0.3.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 +242 -56
- package/dist/assets/worker-DvdTp4yb.js.map +1 -0
- package/dist/{helpers-3TGPHd1h.js → helpers-C0nyU6hv.js} +58 -61
- package/dist/{helpers-3TGPHd1h.js.map → helpers-C0nyU6hv.js.map} +1 -1
- package/dist/helpers-FvdHLObV.cjs +2 -0
- package/dist/{helpers-DjY2OR7f.cjs.map → helpers-FvdHLObV.cjs.map} +1 -1
- package/dist/index.cjs +131 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +161 -152
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +132 -117
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.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 +18 -23
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-BL3varjN.js.map +0 -1
- package/dist/helpers-DjY2OR7f.cjs +0 -2
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { wrap as i
|
|
2
|
-
import { D as
|
|
1
|
+
import { wrap as i } from "comlink";
|
|
2
|
+
import { D as f, F as d, O as p, b as u, a as y, P as w, c as m, S as g, T as v, e as b, k as F, d as E, l as S, h as P, o as x, f as T, m as C, g as D, j as A, n as O, i as _, r as I, s as U, w as R } from "./helpers-C0nyU6hv.js";
|
|
3
3
|
const a = `/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2019 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"),
|
|
8
|
+
const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), A = Symbol("Comlink.finalizer"), E = Symbol("Comlink.thrown"), $ = (e) => typeof e == "object" && e !== null || typeof e == "function", W = {
|
|
9
9
|
canHandle: (e) => $(e) && e[H],
|
|
10
10
|
serialize(e) {
|
|
11
11
|
const { port1: t, port2: r } = new MessageChannel();
|
|
12
|
-
return
|
|
12
|
+
return I(e, t), [r, [r]];
|
|
13
13
|
},
|
|
14
14
|
deserialize(e) {
|
|
15
15
|
return e.start(), Y(e);
|
|
16
16
|
}
|
|
17
17
|
}, j = {
|
|
18
|
-
canHandle: (e) => $(e) &&
|
|
18
|
+
canHandle: (e) => $(e) && E in e,
|
|
19
19
|
serialize({ value: e }) {
|
|
20
20
|
let t;
|
|
21
21
|
return e instanceof Error ? t = {
|
|
@@ -30,7 +30,7 @@ const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("C
|
|
|
30
30
|
deserialize(e) {
|
|
31
31
|
throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, z = /* @__PURE__ */ new Map([
|
|
34
34
|
["proxy", W],
|
|
35
35
|
["throw", j]
|
|
36
36
|
]);
|
|
@@ -40,7 +40,7 @@ function V(e, t) {
|
|
|
40
40
|
return !0;
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function I(e, t = globalThis, r = ["*"]) {
|
|
44
44
|
t.addEventListener("message", function n(i) {
|
|
45
45
|
if (!i || !i.data)
|
|
46
46
|
return;
|
|
@@ -48,7 +48,7 @@ function P(e, t = globalThis, r = ["*"]) {
|
|
|
48
48
|
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const { id: a, type: s, path: o } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(
|
|
51
|
+
const { id: a, type: s, path: o } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(d);
|
|
52
52
|
let h;
|
|
53
53
|
try {
|
|
54
54
|
const u = o.slice(0, -1).reduce((f, g) => f[g], e), w = o.reduce((f, g) => f[g], e);
|
|
@@ -57,7 +57,7 @@ function P(e, t = globalThis, r = ["*"]) {
|
|
|
57
57
|
h = w;
|
|
58
58
|
break;
|
|
59
59
|
case "SET":
|
|
60
|
-
u[o.slice(-1)[0]] =
|
|
60
|
+
u[o.slice(-1)[0]] = d(i.data.value), h = !0;
|
|
61
61
|
break;
|
|
62
62
|
case "APPLY":
|
|
63
63
|
h = w.apply(u, l);
|
|
@@ -71,7 +71,7 @@ function P(e, t = globalThis, r = ["*"]) {
|
|
|
71
71
|
case "ENDPOINT":
|
|
72
72
|
{
|
|
73
73
|
const { port1: f, port2: g } = new MessageChannel();
|
|
74
|
-
|
|
74
|
+
I(e, g), h = J(f, [f]);
|
|
75
75
|
}
|
|
76
76
|
break;
|
|
77
77
|
case "RELEASE":
|
|
@@ -81,15 +81,15 @@ function P(e, t = globalThis, r = ["*"]) {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
} catch (u) {
|
|
84
|
-
h = { value: u, [
|
|
84
|
+
h = { value: u, [E]: 0 };
|
|
85
85
|
}
|
|
86
|
-
Promise.resolve(h).catch((u) => ({ value: u, [
|
|
87
|
-
const [w, f] =
|
|
88
|
-
t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f), s === "RELEASE" && (t.removeEventListener("message", n), L(t),
|
|
86
|
+
Promise.resolve(h).catch((u) => ({ value: u, [E]: 0 })).then((u) => {
|
|
87
|
+
const [w, f] = D(u);
|
|
88
|
+
t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f), s === "RELEASE" && (t.removeEventListener("message", n), L(t), A in e && typeof e[A] == "function" && e[A]());
|
|
89
89
|
}).catch((u) => {
|
|
90
|
-
const [w, f] =
|
|
90
|
+
const [w, f] = D({
|
|
91
91
|
value: new TypeError("Unserializable return value"),
|
|
92
|
-
[
|
|
92
|
+
[E]: 0
|
|
93
93
|
});
|
|
94
94
|
t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f);
|
|
95
95
|
});
|
|
@@ -114,14 +114,14 @@ function Y(e, t) {
|
|
|
114
114
|
} finally {
|
|
115
115
|
r.delete(a.id);
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), x(e, r, [], t);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function p(e) {
|
|
120
120
|
if (e)
|
|
121
121
|
throw new Error("Proxy has been released and is not useable");
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
return
|
|
123
|
+
function U(e) {
|
|
124
|
+
return y(e, /* @__PURE__ */ new Map(), {
|
|
125
125
|
type: "RELEASE"
|
|
126
126
|
}).then(() => {
|
|
127
127
|
L(e);
|
|
@@ -129,7 +129,7 @@ function z(e) {
|
|
|
129
129
|
}
|
|
130
130
|
const F = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
|
|
131
131
|
const t = (F.get(e) || 0) - 1;
|
|
132
|
-
F.set(e, t), t === 0 &&
|
|
132
|
+
F.set(e, t), t === 0 && U(e);
|
|
133
133
|
});
|
|
134
134
|
function X(e, t) {
|
|
135
135
|
const r = (F.get(t) || 0) + 1;
|
|
@@ -138,59 +138,59 @@ function X(e, t) {
|
|
|
138
138
|
function q(e) {
|
|
139
139
|
S && S.unregister(e);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function x(e, t, r = [], n = function() {
|
|
142
142
|
}) {
|
|
143
143
|
let i = !1;
|
|
144
144
|
const a = new Proxy(n, {
|
|
145
145
|
get(s, o) {
|
|
146
|
-
if (
|
|
146
|
+
if (p(i), o === B)
|
|
147
147
|
return () => {
|
|
148
|
-
q(a),
|
|
148
|
+
q(a), U(e), t.clear(), i = !0;
|
|
149
149
|
};
|
|
150
150
|
if (o === "then") {
|
|
151
151
|
if (r.length === 0)
|
|
152
152
|
return { then: () => a };
|
|
153
|
-
const l =
|
|
153
|
+
const l = y(e, t, {
|
|
154
154
|
type: "GET",
|
|
155
155
|
path: r.map((h) => h.toString())
|
|
156
|
-
}).then(
|
|
156
|
+
}).then(d);
|
|
157
157
|
return l.then.bind(l);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
159
|
+
return x(e, t, [...r, o]);
|
|
160
160
|
},
|
|
161
161
|
set(s, o, l) {
|
|
162
|
-
|
|
163
|
-
const [h, u] =
|
|
164
|
-
return
|
|
162
|
+
p(i);
|
|
163
|
+
const [h, u] = D(l);
|
|
164
|
+
return y(e, t, {
|
|
165
165
|
type: "SET",
|
|
166
166
|
path: [...r, o].map((w) => w.toString()),
|
|
167
167
|
value: h
|
|
168
|
-
}, u).then(
|
|
168
|
+
}, u).then(d);
|
|
169
169
|
},
|
|
170
170
|
apply(s, o, l) {
|
|
171
|
-
|
|
171
|
+
p(i);
|
|
172
172
|
const h = r[r.length - 1];
|
|
173
173
|
if (h === R)
|
|
174
|
-
return
|
|
174
|
+
return y(e, t, {
|
|
175
175
|
type: "ENDPOINT"
|
|
176
|
-
}).then(
|
|
176
|
+
}).then(d);
|
|
177
177
|
if (h === "bind")
|
|
178
|
-
return
|
|
179
|
-
const [u, w] =
|
|
180
|
-
return
|
|
178
|
+
return x(e, t, r.slice(0, -1));
|
|
179
|
+
const [u, w] = v(l);
|
|
180
|
+
return y(e, t, {
|
|
181
181
|
type: "APPLY",
|
|
182
182
|
path: r.map((f) => f.toString()),
|
|
183
183
|
argumentList: u
|
|
184
|
-
}, w).then(
|
|
184
|
+
}, w).then(d);
|
|
185
185
|
},
|
|
186
186
|
construct(s, o) {
|
|
187
|
-
|
|
188
|
-
const [l, h] =
|
|
189
|
-
return
|
|
187
|
+
p(i);
|
|
188
|
+
const [l, h] = v(o);
|
|
189
|
+
return y(e, t, {
|
|
190
190
|
type: "CONSTRUCT",
|
|
191
191
|
path: r.map((u) => u.toString()),
|
|
192
192
|
argumentList: l
|
|
193
|
-
}, h).then(
|
|
193
|
+
}, h).then(d);
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
return X(a, e), a;
|
|
@@ -198,8 +198,8 @@ function I(e, t, r = [], n = function() {
|
|
|
198
198
|
function K(e) {
|
|
199
199
|
return Array.prototype.concat.apply([], e);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
const t = e.map(
|
|
201
|
+
function v(e) {
|
|
202
|
+
const t = e.map(D);
|
|
203
203
|
return [t.map((r) => r[0]), K(t.map((r) => r[1]))];
|
|
204
204
|
}
|
|
205
205
|
const _ = /* @__PURE__ */ new WeakMap();
|
|
@@ -209,8 +209,8 @@ function J(e, t) {
|
|
|
209
209
|
function Q(e) {
|
|
210
210
|
return Object.assign(e, { [H]: !0 });
|
|
211
211
|
}
|
|
212
|
-
function
|
|
213
|
-
for (const [t, r] of
|
|
212
|
+
function D(e) {
|
|
213
|
+
for (const [t, r] of z)
|
|
214
214
|
if (r.canHandle(e)) {
|
|
215
215
|
const [n, i] = r.serialize(e);
|
|
216
216
|
return [
|
|
@@ -230,15 +230,15 @@ function A(e) {
|
|
|
230
230
|
_.get(e) || []
|
|
231
231
|
];
|
|
232
232
|
}
|
|
233
|
-
function
|
|
233
|
+
function d(e) {
|
|
234
234
|
switch (e.type) {
|
|
235
235
|
case "HANDLER":
|
|
236
|
-
return
|
|
236
|
+
return z.get(e.name).deserialize(e.value);
|
|
237
237
|
case "RAW":
|
|
238
238
|
return e.value;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
function y(e, t, r, n) {
|
|
242
242
|
return new Promise((i) => {
|
|
243
243
|
const a = Z();
|
|
244
244
|
t.set(a, i), e.start && e.start(), e.postMessage(Object.assign({ id: a }, r), n);
|
|
@@ -257,17 +257,17 @@ class tt extends c {
|
|
|
257
257
|
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
class
|
|
260
|
+
class C extends c {
|
|
261
261
|
constructor() {
|
|
262
262
|
super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
class
|
|
265
|
+
class N extends c {
|
|
266
266
|
constructor(t, r) {
|
|
267
267
|
super(t, "INVALID_PATH", r);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
class
|
|
270
|
+
class b extends c {
|
|
271
271
|
constructor(t) {
|
|
272
272
|
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
|
|
273
273
|
}
|
|
@@ -352,18 +352,18 @@ function ot() {
|
|
|
352
352
|
function m(e) {
|
|
353
353
|
return Array.isArray(e) ? e : e.split("/").filter(Boolean);
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function P(e) {
|
|
356
356
|
return typeof e == "string" ? e ?? "/" : \`/\${e.join("/")}\`;
|
|
357
357
|
}
|
|
358
|
-
function
|
|
358
|
+
function T(e) {
|
|
359
359
|
const t = m(e);
|
|
360
360
|
return t[t.length - 1] || "";
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function O(e) {
|
|
363
363
|
const t = m(e);
|
|
364
|
-
return t.pop(),
|
|
364
|
+
return t.pop(), P(t);
|
|
365
365
|
}
|
|
366
|
-
function
|
|
366
|
+
function M(e) {
|
|
367
367
|
return !e || e === "/" ? "/" : e.startsWith("/") ? e : \`/\${e}\`;
|
|
368
368
|
}
|
|
369
369
|
function ct(e) {
|
|
@@ -376,7 +376,7 @@ function ct(e) {
|
|
|
376
376
|
r.pop();
|
|
377
377
|
} else
|
|
378
378
|
r.push(n);
|
|
379
|
-
return
|
|
379
|
+
return P(r);
|
|
380
380
|
}
|
|
381
381
|
function lt(e, t = "utf-8") {
|
|
382
382
|
return typeof e == "string" ? et(e, t) : e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
@@ -390,7 +390,7 @@ async function ht(e) {
|
|
|
390
390
|
t.close();
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
async function
|
|
393
|
+
async function k(e, t, r, n = {}) {
|
|
394
394
|
let i = null;
|
|
395
395
|
try {
|
|
396
396
|
i = await e.createSyncAccessHandle();
|
|
@@ -408,14 +408,11 @@ async function v(e, t, r, n = {}) {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
-
async function ut(e, t = "SHA-1") {
|
|
412
|
-
e instanceof File && (e = await e.arrayBuffer())
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
} catch (r) {
|
|
417
|
-
throw console.warn(\`Failed to calculate \${t} hash:\`, r), r;
|
|
418
|
-
}
|
|
411
|
+
async function ut(e, t = "SHA-1", r = 50 * 1024 * 1024) {
|
|
412
|
+
if (e instanceof File && (e = await e.arrayBuffer()), e.byteLength > r)
|
|
413
|
+
throw new Error(\`File size \${e.byteLength} bytes exceeds maximum allowed size \${r} bytes\`);
|
|
414
|
+
const n = new Uint8Array(e), i = await crypto.subtle.digest(t, n);
|
|
415
|
+
return Array.from(new Uint8Array(i)).map((s) => s.toString(16).padStart(2, "0")).join("");
|
|
419
416
|
}
|
|
420
417
|
async function ft(e) {
|
|
421
418
|
const t = await e.arrayBuffer();
|
|
@@ -424,20 +421,23 @@ async function ft(e) {
|
|
|
424
421
|
class wt {
|
|
425
422
|
/** Root directory handle for the file system */
|
|
426
423
|
root = null;
|
|
427
|
-
/** Watch event callback */
|
|
428
|
-
watchCallback = null;
|
|
429
424
|
/** Map of watched paths to their last known state */
|
|
430
425
|
watchers = /* @__PURE__ */ new Map();
|
|
431
426
|
/** Interval handle for polling watched paths */
|
|
432
427
|
watchTimer = null;
|
|
433
|
-
/** Polling interval in milliseconds */
|
|
434
|
-
watchInterval = 1e3;
|
|
435
428
|
/** Flag to avoid concurrent scans */
|
|
436
429
|
scanning = !1;
|
|
437
430
|
/** Promise to prevent concurrent mount operations */
|
|
438
431
|
mountingPromise = null;
|
|
439
|
-
/**
|
|
440
|
-
|
|
432
|
+
/** BroadcastChannel instance for sending events */
|
|
433
|
+
broadcastChannel = null;
|
|
434
|
+
/** Configuration options */
|
|
435
|
+
options = {
|
|
436
|
+
watchInterval: 1e3,
|
|
437
|
+
maxFileSize: 50 * 1024 * 1024,
|
|
438
|
+
hashAlgorithm: null,
|
|
439
|
+
broadcastChannel: "opfs-worker"
|
|
440
|
+
};
|
|
441
441
|
/**
|
|
442
442
|
* Notify about internal changes to the file system
|
|
443
443
|
*
|
|
@@ -448,33 +448,39 @@ class wt {
|
|
|
448
448
|
* @param type - The type of change (create, change, delete)
|
|
449
449
|
*/
|
|
450
450
|
async notifyChange(t) {
|
|
451
|
-
if (!this.
|
|
451
|
+
if (!this.options.broadcastChannel)
|
|
452
452
|
return;
|
|
453
453
|
let r;
|
|
454
|
-
if (this.hashAlgorithm && !t.isDirectory && t.type !== "removed")
|
|
454
|
+
if (this.options.hashAlgorithm && !t.isDirectory && t.type !== "removed")
|
|
455
455
|
try {
|
|
456
456
|
const n = await this.stat(t.path);
|
|
457
457
|
n.isFile && n.hash && (r = n.hash);
|
|
458
458
|
} catch (n) {
|
|
459
459
|
console.warn(\`Failed to calculate hash for \${t.path}:\`, n);
|
|
460
460
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
461
|
+
try {
|
|
462
|
+
this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
|
|
463
|
+
const n = {
|
|
464
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
465
|
+
...t,
|
|
466
|
+
...r && { hash: r }
|
|
467
|
+
};
|
|
468
|
+
this.broadcastChannel.postMessage(n);
|
|
469
|
+
} catch (n) {
|
|
470
|
+
console.warn("Failed to send event via BroadcastChannel:", n);
|
|
471
|
+
}
|
|
466
472
|
}
|
|
467
473
|
/**
|
|
468
474
|
* Creates a new OPFSFileSystem instance
|
|
469
475
|
*
|
|
470
|
-
* @param watchCallback - Optional callback for file change events
|
|
471
476
|
* @param options - Optional configuration options
|
|
472
477
|
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
473
478
|
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
479
|
+
* @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)
|
|
474
480
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
475
481
|
*/
|
|
476
|
-
constructor(t
|
|
477
|
-
ot(), t &&
|
|
482
|
+
constructor(t) {
|
|
483
|
+
ot(), t && this.setOptions(t), this.mount("/");
|
|
478
484
|
}
|
|
479
485
|
/**
|
|
480
486
|
* Initialize the file system within a given directory
|
|
@@ -511,22 +517,16 @@ class wt {
|
|
|
511
517
|
}), this.mountingPromise;
|
|
512
518
|
}
|
|
513
519
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
516
|
-
* @param callback - The callback function to invoke when files change
|
|
517
|
-
*/
|
|
518
|
-
setWatchCallback(t) {
|
|
519
|
-
this.watchCallback = t;
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Set configuration options for the file system
|
|
520
|
+
* Update configuration options
|
|
523
521
|
*
|
|
524
522
|
* @param options - Configuration options to update
|
|
525
523
|
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
526
524
|
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
525
|
+
* @param options.maxFileSize - Maximum file size for hashing in bytes
|
|
526
|
+
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
527
527
|
*/
|
|
528
528
|
setOptions(t) {
|
|
529
|
-
t.watchInterval !== void 0 && (this.watchInterval = t.watchInterval), t.hashAlgorithm !== void 0 && (this.hashAlgorithm = t.hashAlgorithm);
|
|
529
|
+
t.watchInterval !== void 0 && (this.options.watchInterval = t.watchInterval), t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel);
|
|
530
530
|
}
|
|
531
531
|
/**
|
|
532
532
|
* Automatically mount the OPFS root if not already mounted
|
|
@@ -566,7 +566,7 @@ class wt {
|
|
|
566
566
|
*/
|
|
567
567
|
async getDirectoryHandle(t, r = !1, n = this.root) {
|
|
568
568
|
if (!n)
|
|
569
|
-
throw new
|
|
569
|
+
throw new C();
|
|
570
570
|
const i = Array.isArray(t) ? t : m(t);
|
|
571
571
|
let a = n;
|
|
572
572
|
for (const s of i)
|
|
@@ -594,10 +594,10 @@ class wt {
|
|
|
594
594
|
*/
|
|
595
595
|
async getFileHandle(t, r = !1, n = this.root) {
|
|
596
596
|
if (!n)
|
|
597
|
-
throw new
|
|
597
|
+
throw new C();
|
|
598
598
|
const i = m(t);
|
|
599
599
|
if (i.length === 0)
|
|
600
|
-
throw new
|
|
600
|
+
throw new N("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
601
601
|
const a = i.pop();
|
|
602
602
|
return (await this.getDirectoryHandle(i, r, n)).getFileHandle(a, { create: r });
|
|
603
603
|
}
|
|
@@ -648,7 +648,7 @@ class wt {
|
|
|
648
648
|
const n = await this.getFileHandle(t, !1), i = await ht(n);
|
|
649
649
|
return r === "binary" ? i : rt(i, r);
|
|
650
650
|
} catch (n) {
|
|
651
|
-
throw console.error(n), new
|
|
651
|
+
throw console.error(n), new b(t);
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
654
|
/**
|
|
@@ -679,7 +679,7 @@ class wt {
|
|
|
679
679
|
async writeFile(t, r, n) {
|
|
680
680
|
await this.ensureMounted();
|
|
681
681
|
const i = await this.getFileHandle(t, !0);
|
|
682
|
-
await
|
|
682
|
+
await k(i, r, n, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
683
683
|
}
|
|
684
684
|
/**
|
|
685
685
|
* Append data to a file
|
|
@@ -706,7 +706,7 @@ class wt {
|
|
|
706
706
|
async appendFile(t, r, n) {
|
|
707
707
|
await this.ensureMounted();
|
|
708
708
|
const i = await this.getFileHandle(t, !0);
|
|
709
|
-
await
|
|
709
|
+
await k(i, r, n, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
710
710
|
}
|
|
711
711
|
/**
|
|
712
712
|
* Create a directory
|
|
@@ -731,7 +731,7 @@ class wt {
|
|
|
731
731
|
*/
|
|
732
732
|
async mkdir(t, r) {
|
|
733
733
|
if (await this.ensureMounted(), !this.root)
|
|
734
|
-
throw new
|
|
734
|
+
throw new C();
|
|
735
735
|
const n = r?.recursive ?? !1, i = m(t);
|
|
736
736
|
let a = this.root;
|
|
737
737
|
for (let s = 0; s < i.length; s++) {
|
|
@@ -740,7 +740,7 @@ class wt {
|
|
|
740
740
|
a = await a.getDirectoryHandle(o, { create: n || s === i.length - 1 });
|
|
741
741
|
} catch (l) {
|
|
742
742
|
throw l.name === "NotFoundError" ? new c(
|
|
743
|
-
\`Parent directory does not exist: \${
|
|
743
|
+
\`Parent directory does not exist: \${P(i.slice(0, s + 1))}\`,
|
|
744
744
|
"ENOENT"
|
|
745
745
|
) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${o}\`, "ENOTDIR") : new c("Failed to create directory", "MKDIR_FAILED");
|
|
746
746
|
}
|
|
@@ -779,7 +779,7 @@ class wt {
|
|
|
779
779
|
isFile: !1,
|
|
780
780
|
isDirectory: !0
|
|
781
781
|
};
|
|
782
|
-
const r =
|
|
782
|
+
const r = T(t), n = await this.getDirectoryHandle(O(t), !1), i = this.options.hashAlgorithm !== null;
|
|
783
783
|
try {
|
|
784
784
|
const s = await (await n.getFileHandle(r, { create: !1 })).getFile(), o = {
|
|
785
785
|
kind: "file",
|
|
@@ -789,9 +789,9 @@ class wt {
|
|
|
789
789
|
isFile: !0,
|
|
790
790
|
isDirectory: !1
|
|
791
791
|
};
|
|
792
|
-
if (i && this.hashAlgorithm)
|
|
792
|
+
if (i && this.options.hashAlgorithm)
|
|
793
793
|
try {
|
|
794
|
-
const l = await ut(s, this.hashAlgorithm);
|
|
794
|
+
const l = await ut(s, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
795
795
|
o.hash = l;
|
|
796
796
|
} catch (l) {
|
|
797
797
|
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
@@ -853,10 +853,10 @@ class wt {
|
|
|
853
853
|
async exists(t) {
|
|
854
854
|
if (await this.ensureMounted(), t === "/")
|
|
855
855
|
return !0;
|
|
856
|
-
const r =
|
|
856
|
+
const r = T(t);
|
|
857
857
|
let n = null;
|
|
858
858
|
try {
|
|
859
|
-
n = await this.getDirectoryHandle(
|
|
859
|
+
n = await this.getDirectoryHandle(O(t), !1);
|
|
860
860
|
} catch (i) {
|
|
861
861
|
throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
|
|
862
862
|
}
|
|
@@ -937,10 +937,10 @@ class wt {
|
|
|
937
937
|
const n = r?.recursive ?? !1, i = r?.force ?? !1;
|
|
938
938
|
if (t === "/")
|
|
939
939
|
throw new c("Cannot remove root directory", "EROOT");
|
|
940
|
-
const a =
|
|
940
|
+
const a = T(t);
|
|
941
941
|
if (!a)
|
|
942
|
-
throw new
|
|
943
|
-
const s = await this.getDirectoryHandle(
|
|
942
|
+
throw new N("Invalid path", t);
|
|
943
|
+
const s = await this.getDirectoryHandle(O(t), !1);
|
|
944
944
|
try {
|
|
945
945
|
await s.removeEntry(a, { recursive: n });
|
|
946
946
|
} catch (o) {
|
|
@@ -974,7 +974,7 @@ class wt {
|
|
|
974
974
|
try {
|
|
975
975
|
const r = ct(t);
|
|
976
976
|
if (!await this.exists(r))
|
|
977
|
-
throw new
|
|
977
|
+
throw new b(r);
|
|
978
978
|
return r;
|
|
979
979
|
} catch (r) {
|
|
980
980
|
throw r instanceof c ? r : new c(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
|
|
@@ -1000,7 +1000,7 @@ class wt {
|
|
|
1000
1000
|
await this.ensureMounted();
|
|
1001
1001
|
try {
|
|
1002
1002
|
if (!await this.exists(t))
|
|
1003
|
-
throw new
|
|
1003
|
+
throw new b(t);
|
|
1004
1004
|
await this.copy(t, r, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: r, type: "added", isDirectory: !1 });
|
|
1005
1005
|
} catch (n) {
|
|
1006
1006
|
throw n instanceof c ? n : new c(\`Failed to rename from \${t} to \${r}\`, "RENAME_FAILED");
|
|
@@ -1062,18 +1062,27 @@ class wt {
|
|
|
1062
1062
|
*/
|
|
1063
1063
|
async watch(t) {
|
|
1064
1064
|
await this.ensureMounted();
|
|
1065
|
-
const r =
|
|
1065
|
+
const r = M(t), n = await this.buildSnapshot(r);
|
|
1066
1066
|
this.watchers.set(r, n), this.watchTimer || (this.watchTimer = setInterval(() => {
|
|
1067
1067
|
this.scanWatches();
|
|
1068
|
-
}, this.watchInterval));
|
|
1068
|
+
}, this.options.watchInterval));
|
|
1069
1069
|
}
|
|
1070
1070
|
/**
|
|
1071
1071
|
* Stop watching a previously watched path
|
|
1072
1072
|
*/
|
|
1073
1073
|
unwatch(t) {
|
|
1074
|
-
const r =
|
|
1074
|
+
const r = M(t);
|
|
1075
1075
|
this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
1076
1076
|
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Dispose of resources and clean up the file system instance
|
|
1079
|
+
*
|
|
1080
|
+
* This method should be called when the file system instance is no longer needed
|
|
1081
|
+
* to properly clean up resources like the broadcast channel and watch timers.
|
|
1082
|
+
*/
|
|
1083
|
+
dispose() {
|
|
1084
|
+
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null), this.watchers.clear();
|
|
1085
|
+
}
|
|
1077
1086
|
async buildSnapshot(t) {
|
|
1078
1087
|
const r = /* @__PURE__ */ new Map(), n = async (i) => {
|
|
1079
1088
|
const a = await this.stat(i);
|
|
@@ -1101,10 +1110,13 @@ class wt {
|
|
|
1101
1110
|
}
|
|
1102
1111
|
for (const [i, a] of n) {
|
|
1103
1112
|
const s = r.get(i);
|
|
1104
|
-
s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: i, type: "changed", isDirectory:
|
|
1113
|
+
s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: i, type: "changed", isDirectory: a.isDirectory }) : await this.notifyChange({ path: i, type: "added", isDirectory: a.isDirectory });
|
|
1105
1114
|
}
|
|
1106
1115
|
for (const i of r.keys())
|
|
1107
|
-
n.has(i)
|
|
1116
|
+
if (!n.has(i)) {
|
|
1117
|
+
const a = r.get(i);
|
|
1118
|
+
await this.notifyChange({ path: i, type: "removed", isDirectory: a?.isDirectory ?? !1 });
|
|
1119
|
+
}
|
|
1108
1120
|
this.watchers.set(t, n);
|
|
1109
1121
|
})
|
|
1110
1122
|
);
|
|
@@ -1146,7 +1158,7 @@ class wt {
|
|
|
1146
1158
|
try {
|
|
1147
1159
|
(r?.cleanBefore ?? !1) && await this.clear("/");
|
|
1148
1160
|
for (const [i, a] of t) {
|
|
1149
|
-
const s =
|
|
1161
|
+
const s = M(i);
|
|
1150
1162
|
let o;
|
|
1151
1163
|
a instanceof Blob ? o = await ft(a) : o = a, await this.writeFile(s, o);
|
|
1152
1164
|
}
|
|
@@ -1156,61 +1168,58 @@ class wt {
|
|
|
1156
1168
|
}
|
|
1157
1169
|
}
|
|
1158
1170
|
}
|
|
1159
|
-
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
1160
|
-
//# sourceMappingURL=worker-
|
|
1171
|
+
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && I(new wt());
|
|
1172
|
+
//# sourceMappingURL=worker-DvdTp4yb.js.map
|
|
1161
1173
|
`, r = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", a], { type: "text/javascript;charset=utf-8" });
|
|
1162
|
-
function
|
|
1174
|
+
function o(t) {
|
|
1163
1175
|
let n;
|
|
1164
1176
|
try {
|
|
1165
1177
|
if (n = r && (self.URL || self.webkitURL).createObjectURL(r), !n) throw "";
|
|
1166
|
-
const
|
|
1178
|
+
const e = new Worker(n, {
|
|
1167
1179
|
type: "module",
|
|
1168
|
-
name:
|
|
1180
|
+
name: t?.name
|
|
1169
1181
|
});
|
|
1170
|
-
return
|
|
1182
|
+
return e.addEventListener("error", () => {
|
|
1171
1183
|
(self.URL || self.webkitURL).revokeObjectURL(n);
|
|
1172
|
-
}),
|
|
1184
|
+
}), e;
|
|
1173
1185
|
} catch {
|
|
1174
1186
|
return new Worker(
|
|
1175
1187
|
"data:text/javascript;charset=utf-8," + encodeURIComponent(a),
|
|
1176
1188
|
{
|
|
1177
1189
|
type: "module",
|
|
1178
|
-
name:
|
|
1190
|
+
name: t?.name
|
|
1179
1191
|
}
|
|
1180
1192
|
);
|
|
1181
1193
|
}
|
|
1182
1194
|
}
|
|
1183
|
-
function
|
|
1184
|
-
const
|
|
1185
|
-
return
|
|
1186
|
-
e ? o(e) : () => {
|
|
1187
|
-
}
|
|
1188
|
-
), n && t.setOptions(n), t;
|
|
1195
|
+
function c(t) {
|
|
1196
|
+
const n = i(new o());
|
|
1197
|
+
return t && n.setOptions(t), n;
|
|
1189
1198
|
}
|
|
1190
1199
|
export {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1200
|
+
f as DirectoryNotFoundError,
|
|
1201
|
+
d as FileNotFoundError,
|
|
1202
|
+
p as OPFSError,
|
|
1203
|
+
u as OPFSNotMountedError,
|
|
1204
|
+
y as OPFSNotSupportedError,
|
|
1205
|
+
w as PathError,
|
|
1206
|
+
m as PermissionError,
|
|
1207
|
+
g as StorageError,
|
|
1208
|
+
v as TimeoutError,
|
|
1209
|
+
b as basename,
|
|
1210
|
+
F as calculateFileHash,
|
|
1211
|
+
E as checkOPFSSupport,
|
|
1212
|
+
S as convertBlobToUint8Array,
|
|
1213
|
+
P as createBuffer,
|
|
1214
|
+
c as createWorker,
|
|
1206
1215
|
x as decodeBuffer,
|
|
1207
|
-
|
|
1208
|
-
|
|
1216
|
+
T as dirname,
|
|
1217
|
+
C as encodeString,
|
|
1209
1218
|
D as extname,
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1219
|
+
A as joinPath,
|
|
1220
|
+
O as normalizePath,
|
|
1221
|
+
_ as readFileData,
|
|
1222
|
+
I as resolvePath,
|
|
1214
1223
|
U as splitPath,
|
|
1215
1224
|
R as writeFileData
|
|
1216
1225
|
};
|