opfs-worker 0.2.2 → 0.2.3
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-CRHhlrlS.js.map +1 -0
- package/dist/index.cjs +316 -304
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +318 -306
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +24 -12
- package/dist/raw.js.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-CMvl9yOu.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
import { wrap as i, proxy as o } from "comlink";
|
|
2
|
-
import { D as u, F as d, O as p, b as w, a as y, P as m, c as g, S as v, T as E, e as S, k as F, d as b, l as P, h as x, o as A, f as T, m as O, g as I, j as _, n as D, i as k, r as
|
|
2
|
+
import { D as u, F as d, O as p, b as w, a as y, P as m, c as g, S as v, T as E, e as S, k as F, d as b, l as P, h as x, o as A, f as T, m as O, g as I, j as _, n as D, i as k, r as R, s as U, w as C } from "./helpers-Co-qCBmA.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"), T = Symbol("Comlink.finalizer"), p = Symbol("Comlink.thrown"), $ = (
|
|
9
|
-
canHandle: (
|
|
10
|
-
serialize(
|
|
11
|
-
const { port1:
|
|
12
|
-
return
|
|
8
|
+
const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), T = Symbol("Comlink.finalizer"), p = Symbol("Comlink.thrown"), $ = (t) => typeof t == "object" && t !== null || typeof t == "function", W = {
|
|
9
|
+
canHandle: (t) => $(t) && t[H],
|
|
10
|
+
serialize(t) {
|
|
11
|
+
const { port1: e, port2: r } = new MessageChannel();
|
|
12
|
+
return x(t, e), [r, [r]];
|
|
13
13
|
},
|
|
14
|
-
deserialize(
|
|
15
|
-
return
|
|
14
|
+
deserialize(t) {
|
|
15
|
+
return t.start(), Y(t);
|
|
16
16
|
}
|
|
17
17
|
}, j = {
|
|
18
|
-
canHandle: (
|
|
19
|
-
serialize({ value:
|
|
20
|
-
let
|
|
21
|
-
return
|
|
18
|
+
canHandle: (t) => $(t) && p in t,
|
|
19
|
+
serialize({ value: t }) {
|
|
20
|
+
let e;
|
|
21
|
+
return t instanceof Error ? e = {
|
|
22
22
|
isError: !0,
|
|
23
23
|
value: {
|
|
24
|
-
message:
|
|
25
|
-
name:
|
|
26
|
-
stack:
|
|
24
|
+
message: t.message,
|
|
25
|
+
name: t.name,
|
|
26
|
+
stack: t.stack
|
|
27
27
|
}
|
|
28
|
-
} :
|
|
28
|
+
} : e = { isError: !1, value: t }, [e, []];
|
|
29
29
|
},
|
|
30
|
-
deserialize(
|
|
31
|
-
throw
|
|
30
|
+
deserialize(t) {
|
|
31
|
+
throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
|
|
32
32
|
}
|
|
33
33
|
}, U = /* @__PURE__ */ new Map([
|
|
34
34
|
["proxy", W],
|
|
35
35
|
["throw", j]
|
|
36
36
|
]);
|
|
37
|
-
function V(
|
|
38
|
-
for (const r of
|
|
39
|
-
if (
|
|
37
|
+
function V(t, e) {
|
|
38
|
+
for (const r of t)
|
|
39
|
+
if (e === r || r === "*" || r instanceof RegExp && r.test(e))
|
|
40
40
|
return !0;
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
43
|
+
function x(t, e = globalThis, r = ["*"]) {
|
|
44
|
+
e.addEventListener("message", function a(n) {
|
|
45
45
|
if (!n || !n.data)
|
|
46
46
|
return;
|
|
47
47
|
if (!V(r, n.origin)) {
|
|
48
48
|
console.warn(\`Invalid origin '\${n.origin}' for comlink proxy\`);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const { id:
|
|
51
|
+
const { id: i, type: o, path: s } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(d);
|
|
52
52
|
let u;
|
|
53
53
|
try {
|
|
54
|
-
const f =
|
|
54
|
+
const f = s.slice(0, -1).reduce((h, g) => h[g], t), w = s.reduce((h, g) => h[g], t);
|
|
55
55
|
switch (o) {
|
|
56
56
|
case "GET":
|
|
57
57
|
u = w;
|
|
58
58
|
break;
|
|
59
59
|
case "SET":
|
|
60
|
-
f[
|
|
60
|
+
f[s.slice(-1)[0]] = d(n.data.value), u = !0;
|
|
61
61
|
break;
|
|
62
62
|
case "APPLY":
|
|
63
63
|
u = w.apply(f, l);
|
|
@@ -71,7 +71,7 @@ function O(e, t = globalThis, r = ["*"]) {
|
|
|
71
71
|
case "ENDPOINT":
|
|
72
72
|
{
|
|
73
73
|
const { port1: h, port2: g } = new MessageChannel();
|
|
74
|
-
|
|
74
|
+
x(t, g), u = J(h, [h]);
|
|
75
75
|
}
|
|
76
76
|
break;
|
|
77
77
|
case "RELEASE":
|
|
@@ -85,138 +85,138 @@ function O(e, t = globalThis, r = ["*"]) {
|
|
|
85
85
|
}
|
|
86
86
|
Promise.resolve(u).catch((f) => ({ value: f, [p]: 0 })).then((f) => {
|
|
87
87
|
const [w, h] = A(f);
|
|
88
|
-
|
|
88
|
+
e.postMessage(Object.assign(Object.assign({}, w), { id: i }), h), o === "RELEASE" && (e.removeEventListener("message", a), L(e), T in t && typeof t[T] == "function" && t[T]());
|
|
89
89
|
}).catch((f) => {
|
|
90
90
|
const [w, h] = A({
|
|
91
91
|
value: new TypeError("Unserializable return value"),
|
|
92
92
|
[p]: 0
|
|
93
93
|
});
|
|
94
|
-
|
|
94
|
+
e.postMessage(Object.assign(Object.assign({}, w), { id: i }), h);
|
|
95
95
|
});
|
|
96
|
-
}),
|
|
96
|
+
}), e.start && e.start();
|
|
97
97
|
}
|
|
98
|
-
function G(
|
|
99
|
-
return
|
|
98
|
+
function G(t) {
|
|
99
|
+
return t.constructor.name === "MessagePort";
|
|
100
100
|
}
|
|
101
|
-
function L(
|
|
102
|
-
G(
|
|
101
|
+
function L(t) {
|
|
102
|
+
G(t) && t.close();
|
|
103
103
|
}
|
|
104
|
-
function Y(
|
|
104
|
+
function Y(t, e) {
|
|
105
105
|
const r = /* @__PURE__ */ new Map();
|
|
106
|
-
return
|
|
107
|
-
const { data:
|
|
108
|
-
if (!
|
|
106
|
+
return t.addEventListener("message", function(n) {
|
|
107
|
+
const { data: i } = n;
|
|
108
|
+
if (!i || !i.id)
|
|
109
109
|
return;
|
|
110
|
-
const o = r.get(
|
|
110
|
+
const o = r.get(i.id);
|
|
111
111
|
if (o)
|
|
112
112
|
try {
|
|
113
|
-
o(
|
|
113
|
+
o(i);
|
|
114
114
|
} finally {
|
|
115
|
-
r.delete(
|
|
115
|
+
r.delete(i.id);
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), O(t, r, [], e);
|
|
118
118
|
}
|
|
119
|
-
function E(
|
|
120
|
-
if (
|
|
119
|
+
function E(t) {
|
|
120
|
+
if (t)
|
|
121
121
|
throw new Error("Proxy has been released and is not useable");
|
|
122
122
|
}
|
|
123
|
-
function z(
|
|
124
|
-
return y(
|
|
123
|
+
function z(t) {
|
|
124
|
+
return y(t, /* @__PURE__ */ new Map(), {
|
|
125
125
|
type: "RELEASE"
|
|
126
126
|
}).then(() => {
|
|
127
|
-
L(
|
|
127
|
+
L(t);
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
const F = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((
|
|
131
|
-
const
|
|
132
|
-
F.set(
|
|
130
|
+
const F = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
|
|
131
|
+
const e = (F.get(t) || 0) - 1;
|
|
132
|
+
F.set(t, e), e === 0 && z(t);
|
|
133
133
|
});
|
|
134
|
-
function X(
|
|
135
|
-
const r = (F.get(
|
|
136
|
-
F.set(
|
|
134
|
+
function X(t, e) {
|
|
135
|
+
const r = (F.get(e) || 0) + 1;
|
|
136
|
+
F.set(e, r), S && S.register(t, e, t);
|
|
137
137
|
}
|
|
138
|
-
function q(
|
|
139
|
-
S && S.unregister(
|
|
138
|
+
function q(t) {
|
|
139
|
+
S && S.unregister(t);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function O(t, e, r = [], a = function() {
|
|
142
142
|
}) {
|
|
143
143
|
let n = !1;
|
|
144
|
-
const
|
|
145
|
-
get(o,
|
|
146
|
-
if (E(n),
|
|
144
|
+
const i = new Proxy(a, {
|
|
145
|
+
get(o, s) {
|
|
146
|
+
if (E(n), s === B)
|
|
147
147
|
return () => {
|
|
148
|
-
q(
|
|
148
|
+
q(i), z(t), e.clear(), n = !0;
|
|
149
149
|
};
|
|
150
|
-
if (
|
|
150
|
+
if (s === "then") {
|
|
151
151
|
if (r.length === 0)
|
|
152
|
-
return { then: () =>
|
|
153
|
-
const l = y(
|
|
152
|
+
return { then: () => i };
|
|
153
|
+
const l = y(t, e, {
|
|
154
154
|
type: "GET",
|
|
155
155
|
path: r.map((u) => u.toString())
|
|
156
156
|
}).then(d);
|
|
157
157
|
return l.then.bind(l);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
159
|
+
return O(t, e, [...r, s]);
|
|
160
160
|
},
|
|
161
|
-
set(o,
|
|
161
|
+
set(o, s, l) {
|
|
162
162
|
E(n);
|
|
163
163
|
const [u, f] = A(l);
|
|
164
|
-
return y(
|
|
164
|
+
return y(t, e, {
|
|
165
165
|
type: "SET",
|
|
166
|
-
path: [...r,
|
|
166
|
+
path: [...r, s].map((w) => w.toString()),
|
|
167
167
|
value: u
|
|
168
168
|
}, f).then(d);
|
|
169
169
|
},
|
|
170
|
-
apply(o,
|
|
170
|
+
apply(o, s, l) {
|
|
171
171
|
E(n);
|
|
172
172
|
const u = r[r.length - 1];
|
|
173
173
|
if (u === R)
|
|
174
|
-
return y(
|
|
174
|
+
return y(t, e, {
|
|
175
175
|
type: "ENDPOINT"
|
|
176
176
|
}).then(d);
|
|
177
177
|
if (u === "bind")
|
|
178
|
-
return
|
|
179
|
-
const [f, w] =
|
|
180
|
-
return y(
|
|
178
|
+
return O(t, e, r.slice(0, -1));
|
|
179
|
+
const [f, w] = N(l);
|
|
180
|
+
return y(t, e, {
|
|
181
181
|
type: "APPLY",
|
|
182
182
|
path: r.map((h) => h.toString()),
|
|
183
183
|
argumentList: f
|
|
184
184
|
}, w).then(d);
|
|
185
185
|
},
|
|
186
|
-
construct(o,
|
|
186
|
+
construct(o, s) {
|
|
187
187
|
E(n);
|
|
188
|
-
const [l, u] =
|
|
189
|
-
return y(
|
|
188
|
+
const [l, u] = N(s);
|
|
189
|
+
return y(t, e, {
|
|
190
190
|
type: "CONSTRUCT",
|
|
191
191
|
path: r.map((f) => f.toString()),
|
|
192
192
|
argumentList: l
|
|
193
193
|
}, u).then(d);
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
|
-
return X(
|
|
196
|
+
return X(i, t), i;
|
|
197
197
|
}
|
|
198
|
-
function K(
|
|
199
|
-
return Array.prototype.concat.apply([],
|
|
198
|
+
function K(t) {
|
|
199
|
+
return Array.prototype.concat.apply([], t);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
const
|
|
203
|
-
return [
|
|
201
|
+
function N(t) {
|
|
202
|
+
const e = t.map(A);
|
|
203
|
+
return [e.map((r) => r[0]), K(e.map((r) => r[1]))];
|
|
204
204
|
}
|
|
205
205
|
const _ = /* @__PURE__ */ new WeakMap();
|
|
206
|
-
function J(
|
|
207
|
-
return _.set(
|
|
206
|
+
function J(t, e) {
|
|
207
|
+
return _.set(t, e), t;
|
|
208
208
|
}
|
|
209
|
-
function Q(
|
|
210
|
-
return Object.assign(
|
|
209
|
+
function Q(t) {
|
|
210
|
+
return Object.assign(t, { [H]: !0 });
|
|
211
211
|
}
|
|
212
|
-
function A(
|
|
213
|
-
for (const [
|
|
214
|
-
if (r.canHandle(
|
|
215
|
-
const [a, n] = r.serialize(
|
|
212
|
+
function A(t) {
|
|
213
|
+
for (const [e, r] of U)
|
|
214
|
+
if (r.canHandle(t)) {
|
|
215
|
+
const [a, n] = r.serialize(t);
|
|
216
216
|
return [
|
|
217
217
|
{
|
|
218
218
|
type: "HANDLER",
|
|
219
|
-
name:
|
|
219
|
+
name: e,
|
|
220
220
|
value: a
|
|
221
221
|
},
|
|
222
222
|
n
|
|
@@ -225,31 +225,31 @@ function A(e) {
|
|
|
225
225
|
return [
|
|
226
226
|
{
|
|
227
227
|
type: "RAW",
|
|
228
|
-
value:
|
|
228
|
+
value: t
|
|
229
229
|
},
|
|
230
|
-
_.get(
|
|
230
|
+
_.get(t) || []
|
|
231
231
|
];
|
|
232
232
|
}
|
|
233
|
-
function d(
|
|
234
|
-
switch (
|
|
233
|
+
function d(t) {
|
|
234
|
+
switch (t.type) {
|
|
235
235
|
case "HANDLER":
|
|
236
|
-
return U.get(
|
|
236
|
+
return U.get(t.name).deserialize(t.value);
|
|
237
237
|
case "RAW":
|
|
238
|
-
return
|
|
238
|
+
return t.value;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function y(
|
|
241
|
+
function y(t, e, r, a) {
|
|
242
242
|
return new Promise((n) => {
|
|
243
|
-
const
|
|
244
|
-
|
|
243
|
+
const i = Z();
|
|
244
|
+
e.set(i, n), t.start && t.start(), t.postMessage(Object.assign({ id: i }, r), a);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
function Z() {
|
|
248
248
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
249
249
|
}
|
|
250
250
|
class c extends Error {
|
|
251
|
-
constructor(
|
|
252
|
-
super(
|
|
251
|
+
constructor(e, r, a) {
|
|
252
|
+
super(e), this.code = r, this.path = a, this.name = "OPFSError";
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
class ee extends c {
|
|
@@ -263,112 +263,112 @@ class D extends c {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
class k extends c {
|
|
266
|
-
constructor(
|
|
267
|
-
super(
|
|
266
|
+
constructor(e, r) {
|
|
267
|
+
super(e, "INVALID_PATH", r);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
class b extends c {
|
|
271
|
-
constructor(
|
|
272
|
-
super(\`File not found: \${
|
|
271
|
+
constructor(e) {
|
|
272
|
+
super(\`File not found: \${e}\`, "FILE_NOT_FOUND", e);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
function te(
|
|
276
|
-
switch (
|
|
275
|
+
function te(t, e = "utf-8") {
|
|
276
|
+
switch (e) {
|
|
277
277
|
case "utf8":
|
|
278
278
|
case "utf-8":
|
|
279
|
-
return new TextEncoder().encode(
|
|
279
|
+
return new TextEncoder().encode(t);
|
|
280
280
|
case "utf16le":
|
|
281
281
|
case "ucs2":
|
|
282
282
|
case "ucs-2":
|
|
283
|
-
return ne(
|
|
283
|
+
return ne(t);
|
|
284
284
|
case "ascii":
|
|
285
|
-
return
|
|
285
|
+
return se(t);
|
|
286
286
|
case "latin1":
|
|
287
|
-
return
|
|
287
|
+
return ie(t);
|
|
288
288
|
case "binary":
|
|
289
|
-
return Uint8Array.from(
|
|
289
|
+
return Uint8Array.from(t, (r) => r.charCodeAt(0));
|
|
290
290
|
case "base64":
|
|
291
|
-
return Uint8Array.from(atob(
|
|
291
|
+
return Uint8Array.from(atob(t), (r) => r.charCodeAt(0));
|
|
292
292
|
case "hex":
|
|
293
|
-
if (!/^[\\da-f]+$/i.test(
|
|
293
|
+
if (!/^[\\da-f]+$/i.test(t) || t.length % 2 !== 0)
|
|
294
294
|
throw new c("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
295
|
-
return Uint8Array.from(
|
|
295
|
+
return Uint8Array.from(t.match(/.{1,2}/g).map((r) => parseInt(r, 16)));
|
|
296
296
|
default:
|
|
297
|
-
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(
|
|
297
|
+
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(t);
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
|
-
function re(
|
|
301
|
-
switch (
|
|
300
|
+
function re(t, e = "utf-8") {
|
|
301
|
+
switch (e) {
|
|
302
302
|
case "utf8":
|
|
303
303
|
case "utf-8":
|
|
304
|
-
return new TextDecoder().decode(
|
|
304
|
+
return new TextDecoder().decode(t);
|
|
305
305
|
case "utf16le":
|
|
306
306
|
case "ucs2":
|
|
307
307
|
case "ucs-2":
|
|
308
|
-
return ae(
|
|
308
|
+
return ae(t);
|
|
309
309
|
case "latin1":
|
|
310
|
-
return String.fromCharCode(...
|
|
310
|
+
return String.fromCharCode(...t);
|
|
311
311
|
case "binary":
|
|
312
|
-
return String.fromCharCode(...
|
|
312
|
+
return String.fromCharCode(...t);
|
|
313
313
|
case "ascii":
|
|
314
|
-
return String.fromCharCode(...
|
|
314
|
+
return String.fromCharCode(...t.map((r) => r & 127));
|
|
315
315
|
case "base64":
|
|
316
|
-
return btoa(String.fromCharCode(...
|
|
316
|
+
return btoa(String.fromCharCode(...t));
|
|
317
317
|
case "hex":
|
|
318
|
-
return Array.from(
|
|
318
|
+
return Array.from(t).map((r) => r.toString(16).padStart(2, "0")).join("");
|
|
319
319
|
default:
|
|
320
|
-
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(
|
|
320
|
+
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(t);
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
function ne(
|
|
324
|
-
const
|
|
325
|
-
for (let r = 0; r <
|
|
326
|
-
const a =
|
|
327
|
-
|
|
323
|
+
function ne(t) {
|
|
324
|
+
const e = new Uint8Array(t.length * 2);
|
|
325
|
+
for (let r = 0; r < t.length; r++) {
|
|
326
|
+
const a = t.charCodeAt(r);
|
|
327
|
+
e[r * 2] = a & 255, e[r * 2 + 1] = a >> 8;
|
|
328
328
|
}
|
|
329
|
-
return
|
|
329
|
+
return e;
|
|
330
330
|
}
|
|
331
|
-
function ae(
|
|
332
|
-
|
|
333
|
-
const
|
|
334
|
-
return String.fromCharCode(...
|
|
331
|
+
function ae(t) {
|
|
332
|
+
t.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), t = t.slice(0, t.length - 1));
|
|
333
|
+
const e = new Uint16Array(t.buffer, t.byteOffset, t.byteLength / 2);
|
|
334
|
+
return String.fromCharCode(...e);
|
|
335
335
|
}
|
|
336
|
-
function
|
|
337
|
-
const
|
|
338
|
-
for (let r = 0; r <
|
|
339
|
-
|
|
340
|
-
return
|
|
336
|
+
function ie(t) {
|
|
337
|
+
const e = new Uint8Array(t.length);
|
|
338
|
+
for (let r = 0; r < t.length; r++)
|
|
339
|
+
e[r] = t.charCodeAt(r) & 255;
|
|
340
|
+
return e;
|
|
341
341
|
}
|
|
342
|
-
function
|
|
343
|
-
const
|
|
344
|
-
for (let r = 0; r <
|
|
345
|
-
|
|
346
|
-
return
|
|
342
|
+
function se(t) {
|
|
343
|
+
const e = new Uint8Array(t.length);
|
|
344
|
+
for (let r = 0; r < t.length; r++)
|
|
345
|
+
e[r] = t.charCodeAt(r) & 127;
|
|
346
|
+
return e;
|
|
347
347
|
}
|
|
348
348
|
function oe() {
|
|
349
349
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
350
350
|
throw new ee();
|
|
351
351
|
}
|
|
352
|
-
function m(
|
|
353
|
-
return Array.isArray(
|
|
352
|
+
function m(t) {
|
|
353
|
+
return Array.isArray(t) ? t : t.split("/").filter(Boolean);
|
|
354
354
|
}
|
|
355
|
-
function
|
|
356
|
-
return typeof
|
|
355
|
+
function v(t) {
|
|
356
|
+
return typeof t == "string" ? t ?? "/" : \`/\${t.join("/")}\`;
|
|
357
357
|
}
|
|
358
|
-
function
|
|
359
|
-
const
|
|
360
|
-
return
|
|
358
|
+
function I(t) {
|
|
359
|
+
const e = m(t);
|
|
360
|
+
return e[e.length - 1] || "";
|
|
361
361
|
}
|
|
362
|
-
function
|
|
363
|
-
const
|
|
364
|
-
return
|
|
362
|
+
function P(t) {
|
|
363
|
+
const e = m(t);
|
|
364
|
+
return e.pop(), v(e);
|
|
365
365
|
}
|
|
366
|
-
function
|
|
367
|
-
return !
|
|
366
|
+
function M(t) {
|
|
367
|
+
return !t || t === "/" ? "/" : t.startsWith("/") ? t : \`/\${t}\`;
|
|
368
368
|
}
|
|
369
|
-
function ce(
|
|
370
|
-
const
|
|
371
|
-
for (const a of
|
|
369
|
+
function ce(t) {
|
|
370
|
+
const e = m(t), r = [];
|
|
371
|
+
for (const a of e)
|
|
372
372
|
if (!(a === "." || a === ""))
|
|
373
373
|
if (a === "..") {
|
|
374
374
|
if (r.length === 0)
|
|
@@ -376,28 +376,28 @@ function ce(e) {
|
|
|
376
376
|
r.pop();
|
|
377
377
|
} else
|
|
378
378
|
r.push(a);
|
|
379
|
-
return
|
|
379
|
+
return v(r);
|
|
380
380
|
}
|
|
381
|
-
function le(
|
|
382
|
-
return typeof
|
|
381
|
+
function le(t, e = "utf-8") {
|
|
382
|
+
return typeof t == "string" ? te(t, e) : t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
383
383
|
}
|
|
384
|
-
async function ue(
|
|
385
|
-
const
|
|
384
|
+
async function ue(t) {
|
|
385
|
+
const e = await t.createSyncAccessHandle();
|
|
386
386
|
try {
|
|
387
|
-
const r =
|
|
388
|
-
return
|
|
387
|
+
const r = e.getSize(), a = new Uint8Array(r);
|
|
388
|
+
return e.read(a, { at: 0 }), a;
|
|
389
389
|
} finally {
|
|
390
|
-
|
|
390
|
+
e.close();
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
async function C(
|
|
393
|
+
async function C(t, e, r, a = {}) {
|
|
394
394
|
let n = null;
|
|
395
395
|
try {
|
|
396
|
-
n = await
|
|
397
|
-
const
|
|
398
|
-
n.write(
|
|
399
|
-
} catch (
|
|
400
|
-
console.error(
|
|
396
|
+
n = await t.createSyncAccessHandle();
|
|
397
|
+
const i = le(e, r), o = a.append ? n.getSize() : 0;
|
|
398
|
+
n.write(i, { at: o }), a.truncate && !a.append && n.truncate(i.byteLength), n.flush();
|
|
399
|
+
} catch (i) {
|
|
400
|
+
console.error(i);
|
|
401
401
|
const o = a.append ? "append" : "write";
|
|
402
402
|
throw new c(\`Failed to \${o} file\`, \`\${o.toUpperCase()}_FAILED\`);
|
|
403
403
|
} finally {
|
|
@@ -408,17 +408,17 @@ async function C(e, t, r, a = {}) {
|
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
|
-
async function fe(
|
|
411
|
+
async function fe(t, e = "SHA-1") {
|
|
412
412
|
try {
|
|
413
|
-
const r = new Uint8Array(
|
|
414
|
-
return Array.from(new Uint8Array(a)).map((
|
|
413
|
+
const r = new Uint8Array(t), a = await crypto.subtle.digest(e, r);
|
|
414
|
+
return Array.from(new Uint8Array(a)).map((i) => i.toString(16).padStart(2, "0")).join("");
|
|
415
415
|
} catch (r) {
|
|
416
|
-
throw console.warn(\`Failed to calculate \${
|
|
416
|
+
throw console.warn(\`Failed to calculate \${e} hash:\`, r), r;
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
|
-
async function he(
|
|
420
|
-
const
|
|
421
|
-
return new Uint8Array(
|
|
419
|
+
async function he(t) {
|
|
420
|
+
const e = await t.arrayBuffer();
|
|
421
|
+
return new Uint8Array(e);
|
|
422
422
|
}
|
|
423
423
|
class we {
|
|
424
424
|
/** Root directory handle for the file system */
|
|
@@ -442,8 +442,8 @@ class we {
|
|
|
442
442
|
* @param watchOptions - Optional configuration for watching
|
|
443
443
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
444
444
|
*/
|
|
445
|
-
constructor(
|
|
446
|
-
oe(),
|
|
445
|
+
constructor(e, r) {
|
|
446
|
+
oe(), e && (this.watchCallback = e, r?.watchInterval && (this.watchInterval = r.watchInterval)), this.mount("/");
|
|
447
447
|
}
|
|
448
448
|
/**
|
|
449
449
|
* Initialize the file system within a given directory
|
|
@@ -466,12 +466,12 @@ class we {
|
|
|
466
466
|
* await fs.mount('/my-app');
|
|
467
467
|
* \`\`\`
|
|
468
468
|
*/
|
|
469
|
-
async mount(
|
|
469
|
+
async mount(e = "/") {
|
|
470
470
|
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (r, a) => {
|
|
471
471
|
this.root = null;
|
|
472
472
|
try {
|
|
473
473
|
const n = await navigator.storage.getDirectory();
|
|
474
|
-
|
|
474
|
+
e === "/" ? this.root = n : this.root = await this.getDirectoryHandle(e, !0, n), r(!0);
|
|
475
475
|
} catch (n) {
|
|
476
476
|
console.error(n), a(new c("Failed to initialize OPFS", "INIT_FAILED"));
|
|
477
477
|
} finally {
|
|
@@ -485,8 +485,8 @@ class we {
|
|
|
485
485
|
* @param callback - The callback function to invoke when files change
|
|
486
486
|
* @param options - Optional configuration for watching
|
|
487
487
|
*/
|
|
488
|
-
setWatchCallback(
|
|
489
|
-
this.watchCallback =
|
|
488
|
+
setWatchCallback(e, r) {
|
|
489
|
+
this.watchCallback = e, r?.watchInterval && (this.watchInterval = r.watchInterval);
|
|
490
490
|
}
|
|
491
491
|
/**
|
|
492
492
|
* Automatically mount the OPFS root if not already mounted
|
|
@@ -524,14 +524,14 @@ class we {
|
|
|
524
524
|
* const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
|
|
525
525
|
* \`\`\`
|
|
526
526
|
*/
|
|
527
|
-
async getDirectoryHandle(
|
|
527
|
+
async getDirectoryHandle(e, r = !1, a = this.root) {
|
|
528
528
|
if (!a)
|
|
529
529
|
throw new D();
|
|
530
|
-
const n = Array.isArray(
|
|
531
|
-
let
|
|
530
|
+
const n = Array.isArray(e) ? e : m(e);
|
|
531
|
+
let i = a;
|
|
532
532
|
for (const o of n)
|
|
533
|
-
|
|
534
|
-
return
|
|
533
|
+
i = await i.getDirectoryHandle(o, { create: r });
|
|
534
|
+
return i;
|
|
535
535
|
}
|
|
536
536
|
/**
|
|
537
537
|
* Get a file handle from a path
|
|
@@ -552,14 +552,14 @@ class we {
|
|
|
552
552
|
* const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
|
|
553
553
|
* \`\`\`
|
|
554
554
|
*/
|
|
555
|
-
async getFileHandle(
|
|
555
|
+
async getFileHandle(e, r = !1, a = this.root) {
|
|
556
556
|
if (!a)
|
|
557
557
|
throw new D();
|
|
558
|
-
const n = m(
|
|
558
|
+
const n = m(e);
|
|
559
559
|
if (n.length === 0)
|
|
560
|
-
throw new k("Path must not be empty", Array.isArray(
|
|
561
|
-
const
|
|
562
|
-
return (await this.getDirectoryHandle(n, r, a)).getFileHandle(
|
|
560
|
+
throw new k("Path must not be empty", Array.isArray(e) ? e.join("/") : e);
|
|
561
|
+
const i = n.pop();
|
|
562
|
+
return (await this.getDirectoryHandle(n, r, a)).getFileHandle(i, { create: r });
|
|
563
563
|
}
|
|
564
564
|
/**
|
|
565
565
|
* Recursively list all files and directories with their stats
|
|
@@ -598,16 +598,16 @@ class we {
|
|
|
598
598
|
* }
|
|
599
599
|
* \`\`\`
|
|
600
600
|
*/
|
|
601
|
-
async index(
|
|
601
|
+
async index(e) {
|
|
602
602
|
const r = /* @__PURE__ */ new Map(), a = async (n) => {
|
|
603
|
-
const
|
|
604
|
-
for (const o of
|
|
605
|
-
const
|
|
603
|
+
const i = await this.readdir(n, { withFileTypes: !0 });
|
|
604
|
+
for (const o of i) {
|
|
605
|
+
const s = \`\${n === "/" ? "" : n}/\${o.name}\`;
|
|
606
606
|
try {
|
|
607
|
-
const l = await this.stat(
|
|
608
|
-
r.set(
|
|
607
|
+
const l = await this.stat(s, e);
|
|
608
|
+
r.set(s, l), l.isDirectory && await a(s);
|
|
609
609
|
} catch (l) {
|
|
610
|
-
console.warn(\`Skipping broken entry: \${
|
|
610
|
+
console.warn(\`Skipping broken entry: \${s}\`, l);
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
613
|
};
|
|
@@ -620,13 +620,13 @@ class we {
|
|
|
620
620
|
isDirectory: !0
|
|
621
621
|
}), await a("/"), r;
|
|
622
622
|
}
|
|
623
|
-
async readFile(
|
|
623
|
+
async readFile(e, r = "utf-8") {
|
|
624
624
|
await this.ensureMounted();
|
|
625
625
|
try {
|
|
626
|
-
const a = await this.getFileHandle(
|
|
626
|
+
const a = await this.getFileHandle(e, !1), n = await ue(a);
|
|
627
627
|
return r === "binary" ? n : re(n, r);
|
|
628
628
|
} catch (a) {
|
|
629
|
-
throw console.error(a), new b(
|
|
629
|
+
throw console.error(a), new b(e);
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
632
|
/**
|
|
@@ -654,9 +654,9 @@ class we {
|
|
|
654
654
|
* await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');
|
|
655
655
|
* \`\`\`
|
|
656
656
|
*/
|
|
657
|
-
async writeFile(
|
|
657
|
+
async writeFile(e, r, a) {
|
|
658
658
|
await this.ensureMounted();
|
|
659
|
-
const n = await this.getFileHandle(
|
|
659
|
+
const n = await this.getFileHandle(e, !0);
|
|
660
660
|
await C(n, r, a, { truncate: !0 });
|
|
661
661
|
}
|
|
662
662
|
/**
|
|
@@ -681,9 +681,9 @@ class we {
|
|
|
681
681
|
* await fs.appendFile('/data/binary.dat', additionalData);
|
|
682
682
|
* \`\`\`
|
|
683
683
|
*/
|
|
684
|
-
async appendFile(
|
|
684
|
+
async appendFile(e, r, a) {
|
|
685
685
|
await this.ensureMounted();
|
|
686
|
-
const n = await this.getFileHandle(
|
|
686
|
+
const n = await this.getFileHandle(e, !0);
|
|
687
687
|
await C(n, r, a, { append: !0 });
|
|
688
688
|
}
|
|
689
689
|
/**
|
|
@@ -707,20 +707,20 @@ class we {
|
|
|
707
707
|
* await fs.mkdir('/users/john/documents/projects', { recursive: true });
|
|
708
708
|
* \`\`\`
|
|
709
709
|
*/
|
|
710
|
-
async mkdir(
|
|
710
|
+
async mkdir(e, r) {
|
|
711
711
|
if (await this.ensureMounted(), !this.root)
|
|
712
712
|
throw new D();
|
|
713
|
-
const a = r?.recursive ?? !1, n = m(
|
|
714
|
-
let
|
|
713
|
+
const a = r?.recursive ?? !1, n = m(e);
|
|
714
|
+
let i = this.root;
|
|
715
715
|
for (let o = 0; o < n.length; o++) {
|
|
716
|
-
const
|
|
716
|
+
const s = n[o];
|
|
717
717
|
try {
|
|
718
|
-
|
|
718
|
+
i = await i.getDirectoryHandle(s, { create: a || o === n.length - 1 });
|
|
719
719
|
} catch (l) {
|
|
720
720
|
throw l.name === "NotFoundError" ? new c(
|
|
721
|
-
\`Parent directory does not exist: \${
|
|
721
|
+
\`Parent directory does not exist: \${v(n.slice(0, o + 1))}\`,
|
|
722
722
|
"ENOENT"
|
|
723
|
-
) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${
|
|
723
|
+
) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${s}\`, "ENOTDIR") : new c("Failed to create directory", "MKDIR_FAILED");
|
|
724
724
|
}
|
|
725
725
|
}
|
|
726
726
|
}
|
|
@@ -753,9 +753,17 @@ class we {
|
|
|
753
753
|
* console.log(\`Hash: \${statsWithHash.hash}\`);
|
|
754
754
|
* \`\`\`
|
|
755
755
|
*/
|
|
756
|
-
async stat(
|
|
757
|
-
await this.ensureMounted()
|
|
758
|
-
|
|
756
|
+
async stat(e, r) {
|
|
757
|
+
if (await this.ensureMounted(), e === "/")
|
|
758
|
+
return {
|
|
759
|
+
kind: "directory",
|
|
760
|
+
size: 0,
|
|
761
|
+
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
762
|
+
ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
763
|
+
isFile: !1,
|
|
764
|
+
isDirectory: !0
|
|
765
|
+
};
|
|
766
|
+
const a = I(e), n = await this.getDirectoryHandle(P(e), !1), i = r?.includeHash ?? !1, o = r?.hashAlgorithm ?? "SHA-1";
|
|
759
767
|
try {
|
|
760
768
|
const l = await (await n.getFileHandle(a, { create: !1 })).getFile(), u = {
|
|
761
769
|
kind: "file",
|
|
@@ -765,16 +773,16 @@ class we {
|
|
|
765
773
|
isFile: !0,
|
|
766
774
|
isDirectory: !1
|
|
767
775
|
};
|
|
768
|
-
if (
|
|
776
|
+
if (i)
|
|
769
777
|
try {
|
|
770
778
|
const f = new Uint8Array(await l.arrayBuffer()), w = await fe(f, o);
|
|
771
779
|
u.hash = w;
|
|
772
780
|
} catch (f) {
|
|
773
|
-
console.warn(\`Failed to calculate hash for \${
|
|
781
|
+
console.warn(\`Failed to calculate hash for \${e}:\`, f);
|
|
774
782
|
}
|
|
775
783
|
return u;
|
|
776
|
-
} catch (
|
|
777
|
-
if (
|
|
784
|
+
} catch (s) {
|
|
785
|
+
if (s.name !== "TypeMismatchError" && s.name !== "NotFoundError")
|
|
778
786
|
throw new c("Failed to stat (file)", "STAT_FAILED");
|
|
779
787
|
}
|
|
780
788
|
try {
|
|
@@ -786,30 +794,30 @@ class we {
|
|
|
786
794
|
isFile: !1,
|
|
787
795
|
isDirectory: !0
|
|
788
796
|
};
|
|
789
|
-
} catch (
|
|
790
|
-
throw
|
|
797
|
+
} catch (s) {
|
|
798
|
+
throw s.name === "NotFoundError" ? new c(\`No such file or directory: \${e}\`, "ENOENT") : new c("Failed to stat (directory)", "STAT_FAILED");
|
|
791
799
|
}
|
|
792
800
|
}
|
|
793
|
-
async readdir(
|
|
801
|
+
async readdir(e, r) {
|
|
794
802
|
await this.ensureMounted();
|
|
795
|
-
const a = r?.withFileTypes ?? !1, n = await this.getDirectoryHandle(
|
|
803
|
+
const a = r?.withFileTypes ?? !1, n = await this.getDirectoryHandle(e, !1);
|
|
796
804
|
if (a) {
|
|
797
|
-
const
|
|
798
|
-
for await (const [o,
|
|
799
|
-
const l =
|
|
800
|
-
|
|
805
|
+
const i = [];
|
|
806
|
+
for await (const [o, s] of n.entries()) {
|
|
807
|
+
const l = s.kind === "file";
|
|
808
|
+
i.push({
|
|
801
809
|
name: o,
|
|
802
|
-
kind:
|
|
810
|
+
kind: s.kind,
|
|
803
811
|
isFile: l,
|
|
804
812
|
isDirectory: !l
|
|
805
813
|
});
|
|
806
814
|
}
|
|
807
|
-
return
|
|
815
|
+
return i;
|
|
808
816
|
} else {
|
|
809
|
-
const
|
|
817
|
+
const i = [];
|
|
810
818
|
for await (const [o] of n.entries())
|
|
811
|
-
|
|
812
|
-
return
|
|
819
|
+
i.push(o);
|
|
820
|
+
return i;
|
|
813
821
|
}
|
|
814
822
|
}
|
|
815
823
|
/**
|
|
@@ -826,12 +834,13 @@ class we {
|
|
|
826
834
|
* console.log(\`File exists: \${exists}\`);
|
|
827
835
|
* \`\`\`
|
|
828
836
|
*/
|
|
829
|
-
async exists(
|
|
830
|
-
await this.ensureMounted()
|
|
831
|
-
|
|
837
|
+
async exists(e) {
|
|
838
|
+
if (await this.ensureMounted(), e === "/")
|
|
839
|
+
return !0;
|
|
840
|
+
const r = I(e);
|
|
832
841
|
let a = null;
|
|
833
842
|
try {
|
|
834
|
-
a = await this.getDirectoryHandle(
|
|
843
|
+
a = await this.getDirectoryHandle(P(e), !1);
|
|
835
844
|
} catch (n) {
|
|
836
845
|
throw (n.name === "NotFoundError" || n.name === "TypeMismatchError") && (a = null), n;
|
|
837
846
|
}
|
|
@@ -870,16 +879,16 @@ class we {
|
|
|
870
879
|
* await fs.clear('/data');
|
|
871
880
|
* \`\`\`
|
|
872
881
|
*/
|
|
873
|
-
async clear(
|
|
882
|
+
async clear(e = "/") {
|
|
874
883
|
await this.ensureMounted();
|
|
875
884
|
try {
|
|
876
|
-
const r = await this.readdir(
|
|
885
|
+
const r = await this.readdir(e, { withFileTypes: !0 });
|
|
877
886
|
for (const a of r) {
|
|
878
|
-
const n = \`\${
|
|
887
|
+
const n = \`\${e === "/" ? "" : e}/\${a.name}\`;
|
|
879
888
|
await this.remove(n, { recursive: !0 });
|
|
880
889
|
}
|
|
881
890
|
} catch (r) {
|
|
882
|
-
throw r instanceof c ? r : new c(\`Failed to clear directory: \${
|
|
891
|
+
throw r instanceof c ? r : new c(\`Failed to clear directory: \${e}\`, "CLEAR_FAILED");
|
|
883
892
|
}
|
|
884
893
|
}
|
|
885
894
|
/**
|
|
@@ -906,19 +915,22 @@ class we {
|
|
|
906
915
|
* await fs.rm('/maybe/exists', { force: true });
|
|
907
916
|
* \`\`\`
|
|
908
917
|
*/
|
|
909
|
-
async remove(
|
|
918
|
+
async remove(e, r) {
|
|
910
919
|
await this.ensureMounted();
|
|
911
|
-
const a = r?.recursive ?? !1, n = r?.force ?? !1
|
|
912
|
-
if (
|
|
913
|
-
throw new
|
|
914
|
-
const
|
|
920
|
+
const a = r?.recursive ?? !1, n = r?.force ?? !1;
|
|
921
|
+
if (e === "/")
|
|
922
|
+
throw new c("Cannot remove root directory", "EROOT");
|
|
923
|
+
const i = I(e);
|
|
924
|
+
if (!i)
|
|
925
|
+
throw new k("Invalid path", e);
|
|
926
|
+
const o = await this.getDirectoryHandle(P(e), !1);
|
|
915
927
|
try {
|
|
916
|
-
await o.removeEntry(
|
|
917
|
-
} catch (
|
|
918
|
-
if (
|
|
928
|
+
await o.removeEntry(i, { recursive: a });
|
|
929
|
+
} catch (s) {
|
|
930
|
+
if (s.name === "NotFoundError") {
|
|
919
931
|
if (!n)
|
|
920
|
-
throw new c(\`No such file or directory: \${
|
|
921
|
-
} else throw
|
|
932
|
+
throw new c(\`No such file or directory: \${e}\`, "ENOENT");
|
|
933
|
+
} else throw s.name === "InvalidModificationError" ? new c(\`Directory not empty: \${e}. Use recursive option to force removal.\`, "ENOTEMPTY") : s.name === "TypeMismatchError" && !a ? new c(\`Cannot remove directory without recursive option: \${e}\`, "EISDIR") : new c(\`Failed to remove path: \${e}\`, "RM_FAILED");
|
|
922
934
|
}
|
|
923
935
|
}
|
|
924
936
|
/**
|
|
@@ -939,15 +951,15 @@ class we {
|
|
|
939
951
|
* console.log(absolute); // '/data/file.txt'
|
|
940
952
|
* \`\`\`
|
|
941
953
|
*/
|
|
942
|
-
async realpath(
|
|
954
|
+
async realpath(e) {
|
|
943
955
|
await this.ensureMounted();
|
|
944
956
|
try {
|
|
945
|
-
const r = ce(
|
|
957
|
+
const r = ce(e);
|
|
946
958
|
if (!await this.exists(r))
|
|
947
959
|
throw new b(r);
|
|
948
960
|
return r;
|
|
949
961
|
} catch (r) {
|
|
950
|
-
throw r instanceof c ? r : new c(\`Failed to resolve path: \${
|
|
962
|
+
throw r instanceof c ? r : new c(\`Failed to resolve path: \${e}\`, "REALPATH_FAILED");
|
|
951
963
|
}
|
|
952
964
|
}
|
|
953
965
|
/**
|
|
@@ -966,14 +978,14 @@ class we {
|
|
|
966
978
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
|
|
967
979
|
* \`\`\`
|
|
968
980
|
*/
|
|
969
|
-
async rename(
|
|
981
|
+
async rename(e, r) {
|
|
970
982
|
await this.ensureMounted();
|
|
971
983
|
try {
|
|
972
|
-
if (!await this.exists(
|
|
973
|
-
throw new b(
|
|
974
|
-
await this.copy(
|
|
984
|
+
if (!await this.exists(e))
|
|
985
|
+
throw new b(e);
|
|
986
|
+
await this.copy(e, r, { recursive: !0 }), await this.remove(e, { recursive: !0 });
|
|
975
987
|
} catch (a) {
|
|
976
|
-
throw a instanceof c ? a : new c(\`Failed to rename from \${
|
|
988
|
+
throw a instanceof c ? a : new c(\`Failed to rename from \${e} to \${r}\`, "RENAME_FAILED");
|
|
977
989
|
}
|
|
978
990
|
}
|
|
979
991
|
/**
|
|
@@ -1001,37 +1013,37 @@ class we {
|
|
|
1001
1013
|
* await fs.copy('/source', '/dest', { recursive: true, force: false });
|
|
1002
1014
|
* \`\`\`
|
|
1003
1015
|
*/
|
|
1004
|
-
async copy(
|
|
1016
|
+
async copy(e, r, a) {
|
|
1005
1017
|
await this.ensureMounted();
|
|
1006
1018
|
try {
|
|
1007
|
-
const n = a?.recursive ?? !1,
|
|
1008
|
-
if (!await this.exists(
|
|
1009
|
-
throw new c(\`Source does not exist: \${
|
|
1010
|
-
if (await this.exists(r) && !
|
|
1019
|
+
const n = a?.recursive ?? !1, i = a?.force ?? !0;
|
|
1020
|
+
if (!await this.exists(e))
|
|
1021
|
+
throw new c(\`Source does not exist: \${e}\`, "ENOENT");
|
|
1022
|
+
if (await this.exists(r) && !i)
|
|
1011
1023
|
throw new c(\`Destination already exists: \${r}\`, "EEXIST");
|
|
1012
|
-
if ((await this.stat(
|
|
1013
|
-
const u = await this.readFile(
|
|
1024
|
+
if ((await this.stat(e)).isFile) {
|
|
1025
|
+
const u = await this.readFile(e, "binary");
|
|
1014
1026
|
await this.writeFile(r, u);
|
|
1015
1027
|
} else {
|
|
1016
1028
|
if (!n)
|
|
1017
|
-
throw new c(\`Cannot copy directory without recursive option: \${
|
|
1029
|
+
throw new c(\`Cannot copy directory without recursive option: \${e}\`, "EISDIR");
|
|
1018
1030
|
await this.mkdir(r, { recursive: !0 });
|
|
1019
|
-
const u = await this.readdir(
|
|
1031
|
+
const u = await this.readdir(e, { withFileTypes: !0 });
|
|
1020
1032
|
for (const f of u) {
|
|
1021
|
-
const w = \`\${
|
|
1022
|
-
await this.copy(w, h, { recursive: !0, force:
|
|
1033
|
+
const w = \`\${e}/\${f.name}\`, h = \`\${r}/\${f.name}\`;
|
|
1034
|
+
await this.copy(w, h, { recursive: !0, force: i });
|
|
1023
1035
|
}
|
|
1024
1036
|
}
|
|
1025
1037
|
} catch (n) {
|
|
1026
|
-
throw n instanceof c ? n : new c(\`Failed to copy from \${
|
|
1038
|
+
throw n instanceof c ? n : new c(\`Failed to copy from \${e} to \${r}\`, "CP_FAILED");
|
|
1027
1039
|
}
|
|
1028
1040
|
}
|
|
1029
1041
|
/**
|
|
1030
1042
|
* Start watching a file or directory for changes
|
|
1031
1043
|
*/
|
|
1032
|
-
async watch(
|
|
1044
|
+
async watch(e) {
|
|
1033
1045
|
await this.ensureMounted();
|
|
1034
|
-
const r =
|
|
1046
|
+
const r = M(e), a = await this.buildSnapshot(r);
|
|
1035
1047
|
this.watchers.set(r, a), this.watchTimer || (this.watchTimer = setInterval(() => {
|
|
1036
1048
|
this.scanWatches();
|
|
1037
1049
|
}, this.watchInterval));
|
|
@@ -1039,46 +1051,46 @@ class we {
|
|
|
1039
1051
|
/**
|
|
1040
1052
|
* Stop watching a previously watched path
|
|
1041
1053
|
*/
|
|
1042
|
-
unwatch(
|
|
1043
|
-
const r =
|
|
1054
|
+
unwatch(e) {
|
|
1055
|
+
const r = M(e);
|
|
1044
1056
|
this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
1045
1057
|
}
|
|
1046
|
-
async buildSnapshot(
|
|
1058
|
+
async buildSnapshot(e) {
|
|
1047
1059
|
const r = /* @__PURE__ */ new Map(), a = async (n) => {
|
|
1048
|
-
const
|
|
1049
|
-
if (r.set(n,
|
|
1060
|
+
const i = await this.stat(n);
|
|
1061
|
+
if (r.set(n, i), i.isDirectory) {
|
|
1050
1062
|
const o = await this.readdir(n, { withFileTypes: !0 });
|
|
1051
|
-
for (const
|
|
1052
|
-
const l = \`\${n === "/" ? "" : n}/\${
|
|
1063
|
+
for (const s of o) {
|
|
1064
|
+
const l = \`\${n === "/" ? "" : n}/\${s.name}\`;
|
|
1053
1065
|
await a(l);
|
|
1054
1066
|
}
|
|
1055
1067
|
}
|
|
1056
1068
|
};
|
|
1057
|
-
return await a(
|
|
1069
|
+
return await a(e), r;
|
|
1058
1070
|
}
|
|
1059
1071
|
async scanWatches() {
|
|
1060
1072
|
if (!this.scanning) {
|
|
1061
1073
|
this.scanning = !0;
|
|
1062
1074
|
try {
|
|
1063
1075
|
await Promise.all(
|
|
1064
|
-
[...this.watchers.entries()].map(async ([
|
|
1076
|
+
[...this.watchers.entries()].map(async ([e, r]) => {
|
|
1065
1077
|
let a;
|
|
1066
1078
|
try {
|
|
1067
|
-
a = await this.buildSnapshot(
|
|
1079
|
+
a = await this.buildSnapshot(e);
|
|
1068
1080
|
} catch {
|
|
1069
1081
|
a = /* @__PURE__ */ new Map();
|
|
1070
1082
|
}
|
|
1071
1083
|
const n = [];
|
|
1072
|
-
for (const [
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1084
|
+
for (const [i, o] of a) {
|
|
1085
|
+
const s = r.get(i);
|
|
1086
|
+
s ? (s.mtime !== o.mtime || s.size !== o.size) && n.push({ path: i, type: "change" }) : n.push({ path: i, type: "create" });
|
|
1075
1087
|
}
|
|
1076
|
-
for (const
|
|
1077
|
-
a.has(
|
|
1088
|
+
for (const i of r.keys())
|
|
1089
|
+
a.has(i) || n.push({ path: i, type: "delete" });
|
|
1078
1090
|
if (n.length && this.watchCallback)
|
|
1079
|
-
for (const
|
|
1080
|
-
this.watchCallback(
|
|
1081
|
-
this.watchers.set(
|
|
1091
|
+
for (const i of n)
|
|
1092
|
+
this.watchCallback(i);
|
|
1093
|
+
this.watchers.set(e, a);
|
|
1082
1094
|
})
|
|
1083
1095
|
);
|
|
1084
1096
|
} finally {
|
|
@@ -1114,22 +1126,22 @@ class we {
|
|
|
1114
1126
|
* await fs.sync(entries, { cleanBefore: true });
|
|
1115
1127
|
* \`\`\`
|
|
1116
1128
|
*/
|
|
1117
|
-
async sync(
|
|
1129
|
+
async sync(e, r) {
|
|
1118
1130
|
await this.ensureMounted();
|
|
1119
1131
|
try {
|
|
1120
1132
|
(r?.cleanBefore ?? !1) && await this.clear("/");
|
|
1121
|
-
for (const [n,
|
|
1122
|
-
const o =
|
|
1123
|
-
let
|
|
1124
|
-
|
|
1133
|
+
for (const [n, i] of e) {
|
|
1134
|
+
const o = M(n);
|
|
1135
|
+
let s;
|
|
1136
|
+
i instanceof Blob ? s = await he(i) : s = i, await this.writeFile(o, s);
|
|
1125
1137
|
}
|
|
1126
1138
|
} catch (a) {
|
|
1127
1139
|
throw a instanceof c ? a : new c("Failed to sync file system", "SYNC_FAILED");
|
|
1128
1140
|
}
|
|
1129
1141
|
}
|
|
1130
1142
|
}
|
|
1131
|
-
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
1132
|
-
//# sourceMappingURL=worker-
|
|
1143
|
+
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && x(new we());
|
|
1144
|
+
//# sourceMappingURL=worker-CRHhlrlS.js.map
|
|
1133
1145
|
`, r = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", a], { type: "text/javascript;charset=utf-8" });
|
|
1134
1146
|
function s(e) {
|
|
1135
1147
|
let n;
|
|
@@ -1179,8 +1191,8 @@ export {
|
|
|
1179
1191
|
_ as joinPath,
|
|
1180
1192
|
D as normalizePath,
|
|
1181
1193
|
k as readFileData,
|
|
1182
|
-
|
|
1194
|
+
R as resolvePath,
|
|
1183
1195
|
U as splitPath,
|
|
1184
|
-
|
|
1196
|
+
C as writeFileData
|
|
1185
1197
|
};
|
|
1186
1198
|
//# sourceMappingURL=index.js.map
|