opfs-worker 1.2.3 → 1.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/dist/assets/worker-1Wh1cr7P.js.map +1 -0
- package/dist/helpers-BuGfPAg0.js +1439 -0
- package/dist/helpers-BuGfPAg0.js.map +1 -0
- package/dist/helpers-CF7A2WQG.cjs +4 -0
- package/dist/helpers-CF7A2WQG.cjs.map +1 -0
- package/dist/index.cjs +717 -601
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +772 -647
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +165 -164
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +74 -19
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/package.json +2 -3
- package/dist/assets/worker-CS9nvwsF.js.map +0 -1
- package/dist/helpers-04x7UBul.cjs +0 -4
- package/dist/helpers-04x7UBul.cjs.map +0 -1
- package/dist/helpers-BXhw_-Ar.js +0 -1330
- package/dist/helpers-BXhw_-Ar.js.map +0 -1
package/dist/raw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expose as
|
|
2
|
-
import {
|
|
3
|
-
class
|
|
1
|
+
import { expose as k, transfer as p } from "comlink";
|
|
2
|
+
import { V as E, u as D, n as z, h as P, r as F, s as x, P as M, w as m, E as d, o as $, c as b, j as S, W as h, p as H, q as v, B as T, O as f, m as l, D as _, H as N, x as A, A as C, g as B, t as R, M as U, K as I, J as O, L as W, l as g, G as L } from "./helpers-BuGfPAg0.js";
|
|
3
|
+
class j {
|
|
4
4
|
/** Root directory handle for the file system */
|
|
5
5
|
root;
|
|
6
6
|
/** Map of watched paths and options */
|
|
@@ -14,7 +14,7 @@ class k {
|
|
|
14
14
|
root: "/",
|
|
15
15
|
namespace: "",
|
|
16
16
|
maxFileSize: 50 * 1024 * 1024,
|
|
17
|
-
hashAlgorithm:
|
|
17
|
+
hashAlgorithm: "etag",
|
|
18
18
|
broadcastChannel: "opfs-worker"
|
|
19
19
|
};
|
|
20
20
|
/** Map of open file descriptors to their metadata */
|
|
@@ -28,7 +28,7 @@ class k {
|
|
|
28
28
|
_getFileDescriptor(t) {
|
|
29
29
|
const e = this.openFiles.get(t);
|
|
30
30
|
if (!e)
|
|
31
|
-
throw new
|
|
31
|
+
throw new E("descriptor", `Invalid file descriptor: ${t}`);
|
|
32
32
|
return e;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -44,12 +44,12 @@ class k {
|
|
|
44
44
|
if (!this.options.broadcastChannel)
|
|
45
45
|
return;
|
|
46
46
|
const e = t.path;
|
|
47
|
-
if (![...this.watchers.values()].some((r) =>
|
|
47
|
+
if (![...this.watchers.values()].some((r) => D(e, r.pattern) && r.include.some((s) => s && D(e, s)) && !r.exclude.some((s) => s && D(e, s))))
|
|
48
48
|
return;
|
|
49
|
-
let
|
|
49
|
+
let i;
|
|
50
50
|
if (this.options.hashAlgorithm)
|
|
51
51
|
try {
|
|
52
|
-
|
|
52
|
+
i = (await this.stat(e)).hash;
|
|
53
53
|
} catch {
|
|
54
54
|
}
|
|
55
55
|
try {
|
|
@@ -58,7 +58,7 @@ class k {
|
|
|
58
58
|
namespace: this.options.namespace,
|
|
59
59
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
60
60
|
...t,
|
|
61
|
-
...
|
|
61
|
+
...i && { hash: i }
|
|
62
62
|
};
|
|
63
63
|
this.broadcastChannel.postMessage(r);
|
|
64
64
|
} catch (r) {
|
|
@@ -76,7 +76,7 @@ class k {
|
|
|
76
76
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
77
77
|
*/
|
|
78
78
|
constructor(t) {
|
|
79
|
-
|
|
79
|
+
z(), t && this.setOptions(t);
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Initialize the file system within a given directory
|
|
@@ -101,12 +101,12 @@ class k {
|
|
|
101
101
|
*/
|
|
102
102
|
async mount() {
|
|
103
103
|
const t = this.options.root;
|
|
104
|
-
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e,
|
|
104
|
+
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, a) => {
|
|
105
105
|
try {
|
|
106
|
-
const
|
|
107
|
-
this.root = t === "/" ?
|
|
108
|
-
} catch (
|
|
109
|
-
|
|
106
|
+
const i = await navigator.storage.getDirectory();
|
|
107
|
+
this.root = t === "/" ? i : await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
108
|
+
} catch (i) {
|
|
109
|
+
a(new P(t, i));
|
|
110
110
|
} finally {
|
|
111
111
|
this.mountingPromise = null;
|
|
112
112
|
}
|
|
@@ -143,10 +143,10 @@ class k {
|
|
|
143
143
|
* const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
|
|
144
144
|
* ```
|
|
145
145
|
*/
|
|
146
|
-
async getDirectoryHandle(t, e = !1,
|
|
147
|
-
const
|
|
148
|
-
let r =
|
|
149
|
-
for (const s of
|
|
146
|
+
async getDirectoryHandle(t, e = !1, a = this.root) {
|
|
147
|
+
const i = Array.isArray(t) ? t : x(t);
|
|
148
|
+
let r = a;
|
|
149
|
+
for (const s of i)
|
|
150
150
|
r = await r.getDirectoryHandle(s, { create: e });
|
|
151
151
|
return r;
|
|
152
152
|
}
|
|
@@ -169,12 +169,12 @@ class k {
|
|
|
169
169
|
* const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
|
|
170
170
|
* ```
|
|
171
171
|
*/
|
|
172
|
-
async getFileHandle(t, e = !1,
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
throw new
|
|
176
|
-
const r =
|
|
177
|
-
return (await this.getDirectoryHandle(
|
|
172
|
+
async getFileHandle(t, e = !1, a = this.root) {
|
|
173
|
+
const i = x(t);
|
|
174
|
+
if (i.length === 0)
|
|
175
|
+
throw new M("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
176
|
+
const r = i.pop();
|
|
177
|
+
return (await this.getDirectoryHandle(i, e, a)).getFileHandle(r, { create: e });
|
|
178
178
|
}
|
|
179
179
|
/**
|
|
180
180
|
* Get a complete index of all files and directories in the file system
|
|
@@ -196,10 +196,10 @@ class k {
|
|
|
196
196
|
* ```
|
|
197
197
|
*/
|
|
198
198
|
async index() {
|
|
199
|
-
const t = /* @__PURE__ */ new Map(), e = async (
|
|
200
|
-
const
|
|
201
|
-
for (const r of
|
|
202
|
-
const s = `${
|
|
199
|
+
const t = /* @__PURE__ */ new Map(), e = async (a) => {
|
|
200
|
+
const i = await this.readDir(a);
|
|
201
|
+
for (const r of i) {
|
|
202
|
+
const s = `${a === "/" ? "" : a}/${r.name}`;
|
|
203
203
|
try {
|
|
204
204
|
const n = await this.stat(s);
|
|
205
205
|
t.set(s, n), n.isDirectory && await e(s);
|
|
@@ -239,17 +239,17 @@ class k {
|
|
|
239
239
|
async readFile(t) {
|
|
240
240
|
await this.mount();
|
|
241
241
|
try {
|
|
242
|
-
return await
|
|
242
|
+
return await m(t, "shared", async () => {
|
|
243
243
|
const e = await this.open(t);
|
|
244
244
|
try {
|
|
245
|
-
const { size:
|
|
246
|
-
return
|
|
245
|
+
const { size: a } = await this.fstat(e), i = new Uint8Array(a);
|
|
246
|
+
return a > 0 && await this.read(e, i, 0, a, 0), p(i, [i.buffer]);
|
|
247
247
|
} finally {
|
|
248
248
|
await this.close(e);
|
|
249
249
|
}
|
|
250
250
|
});
|
|
251
251
|
} catch (e) {
|
|
252
|
-
throw new
|
|
252
|
+
throw new d("file", t, e);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
@@ -276,15 +276,15 @@ class k {
|
|
|
276
276
|
*/
|
|
277
277
|
async writeFile(t, e) {
|
|
278
278
|
await this.mount();
|
|
279
|
-
const
|
|
280
|
-
await
|
|
281
|
-
const
|
|
279
|
+
const a = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
280
|
+
await m(t, "exclusive", async () => {
|
|
281
|
+
const i = await this.exists(t), r = await this.open(t, { create: !0, truncate: !0 });
|
|
282
282
|
try {
|
|
283
|
-
await this.write(r,
|
|
283
|
+
await this.write(r, a, 0, a.length, null, !1), await this.fsync(r);
|
|
284
284
|
} finally {
|
|
285
285
|
await this.close(r);
|
|
286
286
|
}
|
|
287
|
-
await this.notifyChange({ path: t, type:
|
|
287
|
+
await this.notifyChange({ path: t, type: i ? h.Changed : h.Added, isDirectory: !1 });
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
@@ -311,16 +311,16 @@ class k {
|
|
|
311
311
|
*/
|
|
312
312
|
async appendFile(t, e) {
|
|
313
313
|
await this.mount();
|
|
314
|
-
const
|
|
315
|
-
await
|
|
316
|
-
const
|
|
314
|
+
const a = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
315
|
+
await m(t, "exclusive", async () => {
|
|
316
|
+
const i = await this.open(t, { create: !0 });
|
|
317
317
|
try {
|
|
318
|
-
const { size: r } = await this.fstat(
|
|
319
|
-
await this.write(
|
|
318
|
+
const { size: r } = await this.fstat(i);
|
|
319
|
+
await this.write(i, a, 0, a.length, r, !1), await this.fsync(i);
|
|
320
320
|
} finally {
|
|
321
|
-
await this.close(
|
|
321
|
+
await this.close(i);
|
|
322
322
|
}
|
|
323
|
-
await this.notifyChange({ path: t, type:
|
|
323
|
+
await this.notifyChange({ path: t, type: h.Changed, isDirectory: !1 });
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
@@ -346,22 +346,17 @@ class k {
|
|
|
346
346
|
*/
|
|
347
347
|
async mkdir(t, e) {
|
|
348
348
|
await this.mount();
|
|
349
|
-
const
|
|
349
|
+
const a = e?.recursive ?? !1, i = x(t);
|
|
350
350
|
let r = this.root;
|
|
351
|
-
for (let s = 0; s <
|
|
352
|
-
const n =
|
|
351
|
+
for (let s = 0; s < i.length; s++) {
|
|
352
|
+
const n = i[s];
|
|
353
353
|
try {
|
|
354
|
-
r = await r.getDirectoryHandle(n, { create:
|
|
355
|
-
} catch (
|
|
356
|
-
throw
|
|
357
|
-
`Parent directory does not exist: ${H(a.slice(0, s + 1))}`,
|
|
358
|
-
"ENOENT",
|
|
359
|
-
void 0,
|
|
360
|
-
c
|
|
361
|
-
) : c.name === "TypeMismatchError" ? new o(`Path segment is not a directory: ${n}`, "ENOTDIR", void 0, c) : new o("Failed to create directory", "MKDIR_FAILED", void 0, c);
|
|
354
|
+
r = await r.getDirectoryHandle(n, { create: a || s === i.length - 1 });
|
|
355
|
+
} catch (o) {
|
|
356
|
+
throw o.name === "NotFoundError" ? new d("directory", $(i.slice(0, s + 1)), o) : o.name === "TypeMismatchError" ? new b("directory", "file", n, o) : new S("create directory", n, o);
|
|
362
357
|
}
|
|
363
358
|
}
|
|
364
|
-
await this.notifyChange({ path: t, type:
|
|
359
|
+
await this.notifyChange({ path: t, type: h.Added, isDirectory: !0 });
|
|
365
360
|
}
|
|
366
361
|
/**
|
|
367
362
|
* Get file or directory statistics
|
|
@@ -395,9 +390,11 @@ class k {
|
|
|
395
390
|
isFile: !1,
|
|
396
391
|
isDirectory: !0
|
|
397
392
|
};
|
|
398
|
-
const e =
|
|
393
|
+
const e = H(t);
|
|
394
|
+
let a;
|
|
399
395
|
try {
|
|
400
|
-
|
|
396
|
+
a = await this.getDirectoryHandle(v(t), !1);
|
|
397
|
+
const i = this.options.hashAlgorithm, s = await (await a.getFileHandle(e, { create: !1 })).getFile(), n = {
|
|
401
398
|
kind: "file",
|
|
402
399
|
size: s.size,
|
|
403
400
|
mtime: new Date(s.lastModified).toISOString(),
|
|
@@ -405,20 +402,24 @@ class k {
|
|
|
405
402
|
isFile: !0,
|
|
406
403
|
isDirectory: !1
|
|
407
404
|
};
|
|
408
|
-
if (
|
|
405
|
+
if (i === "etag")
|
|
406
|
+
n.hash = `${s.lastModified.toString(36)}-${s.size.toString(36)}`;
|
|
407
|
+
else if (typeof i == "string")
|
|
409
408
|
try {
|
|
410
|
-
const
|
|
411
|
-
n.hash =
|
|
412
|
-
} catch (
|
|
413
|
-
console.warn(`Failed to calculate hash for ${t}:`,
|
|
409
|
+
const o = await T(s, i, this.options.maxFileSize);
|
|
410
|
+
n.hash = o;
|
|
411
|
+
} catch (o) {
|
|
412
|
+
console.warn(`Failed to calculate hash for ${t}:`, o);
|
|
414
413
|
}
|
|
415
414
|
return n;
|
|
416
|
-
} catch (
|
|
417
|
-
if (
|
|
418
|
-
throw new
|
|
415
|
+
} catch (i) {
|
|
416
|
+
if (i.name === "NotFoundError")
|
|
417
|
+
throw new d("file", t, i);
|
|
418
|
+
if (i.name !== "TypeMismatchError")
|
|
419
|
+
throw new S("stat", t, i);
|
|
419
420
|
}
|
|
420
421
|
try {
|
|
421
|
-
return await
|
|
422
|
+
return await a.getDirectoryHandle(e, { create: !1 }), {
|
|
422
423
|
kind: "directory",
|
|
423
424
|
size: 0,
|
|
424
425
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -426,8 +427,8 @@ class k {
|
|
|
426
427
|
isFile: !1,
|
|
427
428
|
isDirectory: !0
|
|
428
429
|
};
|
|
429
|
-
} catch (
|
|
430
|
-
throw
|
|
430
|
+
} catch (i) {
|
|
431
|
+
throw new S("stat", t, i);
|
|
431
432
|
}
|
|
432
433
|
}
|
|
433
434
|
/**
|
|
@@ -450,17 +451,17 @@ class k {
|
|
|
450
451
|
*/
|
|
451
452
|
async readDir(t) {
|
|
452
453
|
await this.mount();
|
|
453
|
-
const e = await this.getDirectoryHandle(t, !1),
|
|
454
|
-
for await (const [
|
|
454
|
+
const e = await this.getDirectoryHandle(t, !1), a = [];
|
|
455
|
+
for await (const [i, r] of e.entries()) {
|
|
455
456
|
const s = r.kind === "file";
|
|
456
|
-
|
|
457
|
-
name:
|
|
457
|
+
a.push({
|
|
458
|
+
name: i,
|
|
458
459
|
kind: r.kind,
|
|
459
460
|
isFile: s,
|
|
460
461
|
isDirectory: !s
|
|
461
462
|
});
|
|
462
463
|
}
|
|
463
|
-
return
|
|
464
|
+
return a;
|
|
464
465
|
}
|
|
465
466
|
/**
|
|
466
467
|
* Check if a file or directory exists
|
|
@@ -479,23 +480,23 @@ class k {
|
|
|
479
480
|
async exists(t) {
|
|
480
481
|
if (await this.mount(), t === "/")
|
|
481
482
|
return !0;
|
|
482
|
-
const e =
|
|
483
|
-
let
|
|
483
|
+
const e = H(t);
|
|
484
|
+
let a = null;
|
|
484
485
|
try {
|
|
485
|
-
|
|
486
|
-
} catch (
|
|
487
|
-
if (
|
|
488
|
-
throw
|
|
486
|
+
a = await this.getDirectoryHandle(v(t), !1);
|
|
487
|
+
} catch (i) {
|
|
488
|
+
if (a = null, i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
489
|
+
throw i;
|
|
489
490
|
}
|
|
490
|
-
if (!
|
|
491
|
+
if (!a || !e)
|
|
491
492
|
return !1;
|
|
492
493
|
try {
|
|
493
|
-
return await
|
|
494
|
-
} catch (
|
|
495
|
-
if (
|
|
496
|
-
throw
|
|
494
|
+
return await a.getFileHandle(e, { create: !1 }), !0;
|
|
495
|
+
} catch (i) {
|
|
496
|
+
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
497
|
+
throw i;
|
|
497
498
|
try {
|
|
498
|
-
return await
|
|
499
|
+
return await a.getDirectoryHandle(e, { create: !1 }), !0;
|
|
499
500
|
} catch (r) {
|
|
500
501
|
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
501
502
|
throw r;
|
|
@@ -526,13 +527,13 @@ class k {
|
|
|
526
527
|
await this.mount();
|
|
527
528
|
try {
|
|
528
529
|
const e = await this.readDir(t);
|
|
529
|
-
for (const
|
|
530
|
-
const
|
|
531
|
-
await this.remove(
|
|
530
|
+
for (const a of e) {
|
|
531
|
+
const i = `${t === "/" ? "" : t}/${a.name}`;
|
|
532
|
+
await this.remove(i, { recursive: !0 });
|
|
532
533
|
}
|
|
533
|
-
await this.notifyChange({ path: t, type:
|
|
534
|
+
await this.notifyChange({ path: t, type: h.Changed, isDirectory: !0 });
|
|
534
535
|
} catch (e) {
|
|
535
|
-
throw e instanceof
|
|
536
|
+
throw e instanceof f ? e : l(e, { path: t, isDirectory: !0 });
|
|
536
537
|
}
|
|
537
538
|
}
|
|
538
539
|
/**
|
|
@@ -561,9 +562,9 @@ class k {
|
|
|
561
562
|
*/
|
|
562
563
|
async remove(t, e) {
|
|
563
564
|
if (await this.mount(), t === "/")
|
|
564
|
-
throw new
|
|
565
|
-
const { recursive:
|
|
566
|
-
await
|
|
565
|
+
throw new _("root", t);
|
|
566
|
+
const { recursive: a = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(v(t), !1), s = await this.stat(t);
|
|
567
|
+
await N(r, t, { recursive: a, force: i }), await this.notifyChange({ path: t, type: h.Removed, isDirectory: s.isDirectory });
|
|
567
568
|
}
|
|
568
569
|
/**
|
|
569
570
|
* Resolve a path to an absolute path
|
|
@@ -586,12 +587,12 @@ class k {
|
|
|
586
587
|
async realpath(t) {
|
|
587
588
|
await this.mount();
|
|
588
589
|
try {
|
|
589
|
-
const e =
|
|
590
|
+
const e = A(t);
|
|
590
591
|
if (!await this.exists(e))
|
|
591
|
-
throw new
|
|
592
|
+
throw new d("file", e);
|
|
592
593
|
return e;
|
|
593
594
|
} catch (e) {
|
|
594
|
-
throw e instanceof
|
|
595
|
+
throw e instanceof f ? e : l(e, { path: t });
|
|
595
596
|
}
|
|
596
597
|
}
|
|
597
598
|
/**
|
|
@@ -616,15 +617,15 @@ class k {
|
|
|
616
617
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
617
618
|
* ```
|
|
618
619
|
*/
|
|
619
|
-
async rename(t, e,
|
|
620
|
+
async rename(t, e, a) {
|
|
620
621
|
await this.mount();
|
|
621
622
|
try {
|
|
622
|
-
const
|
|
623
|
-
if (await this.exists(e) && !
|
|
624
|
-
throw new
|
|
625
|
-
await this.copy(t, e, { recursive: !0, overwrite:
|
|
626
|
-
} catch (
|
|
627
|
-
throw
|
|
623
|
+
const i = a?.overwrite ?? !1, r = await this.stat(t);
|
|
624
|
+
if (await this.exists(e) && !i)
|
|
625
|
+
throw new C(e);
|
|
626
|
+
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: h.Removed, isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: h.Added, isDirectory: r.isDirectory });
|
|
627
|
+
} catch (i) {
|
|
628
|
+
throw i instanceof f ? i : l(i, { path: t });
|
|
628
629
|
}
|
|
629
630
|
}
|
|
630
631
|
/**
|
|
@@ -652,29 +653,29 @@ class k {
|
|
|
652
653
|
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
653
654
|
* ```
|
|
654
655
|
*/
|
|
655
|
-
async copy(t, e,
|
|
656
|
+
async copy(t, e, a) {
|
|
656
657
|
await this.mount();
|
|
657
658
|
try {
|
|
658
|
-
const
|
|
659
|
+
const i = a?.recursive ?? !1, r = a?.overwrite ?? !0;
|
|
659
660
|
if (!await this.exists(t))
|
|
660
|
-
throw new
|
|
661
|
+
throw new d("source", t);
|
|
661
662
|
if (await this.exists(e) && !r)
|
|
662
|
-
throw new
|
|
663
|
+
throw new C(e);
|
|
663
664
|
if ((await this.stat(t)).isFile) {
|
|
664
|
-
const
|
|
665
|
-
await this.writeFile(e,
|
|
665
|
+
const c = await this.readFile(t);
|
|
666
|
+
await this.writeFile(e, c);
|
|
666
667
|
} else {
|
|
667
|
-
if (!
|
|
668
|
-
throw new
|
|
668
|
+
if (!i)
|
|
669
|
+
throw new b("file", "directory", t);
|
|
669
670
|
await this.mkdir(e, { recursive: !0 });
|
|
670
|
-
const
|
|
671
|
-
for (const w of
|
|
672
|
-
const
|
|
673
|
-
await this.copy(
|
|
671
|
+
const c = await this.readDir(t);
|
|
672
|
+
for (const w of c) {
|
|
673
|
+
const y = `${t}/${w.name}`, u = `${e}/${w.name}`;
|
|
674
|
+
await this.copy(y, u, { recursive: !0, overwrite: r });
|
|
674
675
|
}
|
|
675
676
|
}
|
|
676
|
-
} catch (
|
|
677
|
-
throw
|
|
677
|
+
} catch (i) {
|
|
678
|
+
throw i instanceof f ? i : l(i, { path: t });
|
|
678
679
|
}
|
|
679
680
|
}
|
|
680
681
|
/**
|
|
@@ -704,13 +705,13 @@ class k {
|
|
|
704
705
|
*/
|
|
705
706
|
async watch(t, e) {
|
|
706
707
|
if (!this.options.broadcastChannel)
|
|
707
|
-
throw new
|
|
708
|
-
const
|
|
709
|
-
pattern:
|
|
708
|
+
throw new B("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
|
|
709
|
+
const a = {
|
|
710
|
+
pattern: R(t, e?.recursive ?? !0),
|
|
710
711
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
711
712
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
712
713
|
};
|
|
713
|
-
this.watchers.set(t,
|
|
714
|
+
this.watchers.set(t, a);
|
|
714
715
|
}
|
|
715
716
|
/**
|
|
716
717
|
* Stop watching a previously watched path
|
|
@@ -747,34 +748,34 @@ class k {
|
|
|
747
748
|
*/
|
|
748
749
|
async open(t, e) {
|
|
749
750
|
await this.mount();
|
|
750
|
-
const { create:
|
|
751
|
+
const { create: a = !1, exclusive: i = !1, truncate: r = !1 } = e || {}, s = F(A(t));
|
|
751
752
|
try {
|
|
752
|
-
return
|
|
753
|
+
return a && i ? await m(s, "exclusive", async () => {
|
|
753
754
|
if (await this.exists(s))
|
|
754
|
-
throw new
|
|
755
|
-
return this._openFile(s,
|
|
756
|
-
}) : await this._openFile(s,
|
|
755
|
+
throw new C(s);
|
|
756
|
+
return this._openFile(s, a, r);
|
|
757
|
+
}) : await this._openFile(s, a, r);
|
|
757
758
|
} catch (n) {
|
|
758
|
-
throw n instanceof
|
|
759
|
+
throw n instanceof f ? n : l(n, { path: s, isDirectory: !1 });
|
|
759
760
|
}
|
|
760
761
|
}
|
|
761
762
|
/**
|
|
762
763
|
* Internal method to open a file (without locking)
|
|
763
764
|
* @private
|
|
764
765
|
*/
|
|
765
|
-
async _openFile(t, e,
|
|
766
|
-
const
|
|
766
|
+
async _openFile(t, e, a) {
|
|
767
|
+
const i = await this.getFileHandle(t, e);
|
|
767
768
|
try {
|
|
768
|
-
await
|
|
769
|
+
await i.getFile();
|
|
769
770
|
} catch (n) {
|
|
770
|
-
throw n
|
|
771
|
+
throw l(n, { path: t, isDirectory: !0 });
|
|
771
772
|
}
|
|
772
|
-
const r = await
|
|
773
|
-
|
|
773
|
+
const r = await U(i, t);
|
|
774
|
+
a && (r.truncate(0), r.flush());
|
|
774
775
|
const s = this.nextFd++;
|
|
775
776
|
return this.openFiles.set(s, {
|
|
776
777
|
path: t,
|
|
777
|
-
fileHandle:
|
|
778
|
+
fileHandle: i,
|
|
778
779
|
syncHandle: r,
|
|
779
780
|
position: 0
|
|
780
781
|
}), s;
|
|
@@ -821,17 +822,17 @@ class k {
|
|
|
821
822
|
* await fs.close(fd);
|
|
822
823
|
* ```
|
|
823
824
|
*/
|
|
824
|
-
async read(t, e,
|
|
825
|
+
async read(t, e, a, i, r) {
|
|
825
826
|
const s = this._getFileDescriptor(t);
|
|
826
|
-
|
|
827
|
+
O(e.length, a, i, r);
|
|
827
828
|
try {
|
|
828
|
-
const n = r ?? s.position,
|
|
829
|
-
if (
|
|
830
|
-
return
|
|
831
|
-
const
|
|
832
|
-
return r == null && (s.position = n +
|
|
829
|
+
const n = r ?? s.position, o = s.syncHandle.getSize(), { isEOF: c, actualLength: w } = W(n, i, o);
|
|
830
|
+
if (c)
|
|
831
|
+
return p({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
832
|
+
const y = e.subarray(a, a + w), u = s.syncHandle.read(y, { at: n });
|
|
833
|
+
return r == null && (s.position = n + u), p({ bytesRead: u, buffer: e }, [e.buffer]);
|
|
833
834
|
} catch (n) {
|
|
834
|
-
throw
|
|
835
|
+
throw g("read", t, s.path, n);
|
|
835
836
|
}
|
|
836
837
|
}
|
|
837
838
|
/**
|
|
@@ -855,14 +856,14 @@ class k {
|
|
|
855
856
|
* await fs.close(fd);
|
|
856
857
|
* ```
|
|
857
858
|
*/
|
|
858
|
-
async write(t, e,
|
|
859
|
-
const n = this._getFileDescriptor(t),
|
|
860
|
-
|
|
859
|
+
async write(t, e, a = 0, i, r, s = !0) {
|
|
860
|
+
const n = this._getFileDescriptor(t), o = i ?? e.length - a;
|
|
861
|
+
O(e.length, a, o, r);
|
|
861
862
|
try {
|
|
862
|
-
const
|
|
863
|
-
return (r == null || r === n.position) && (n.position =
|
|
864
|
-
} catch (
|
|
865
|
-
throw
|
|
863
|
+
const c = r ?? n.position, w = e.subarray(a, a + o), y = n.syncHandle.write(w, { at: c });
|
|
864
|
+
return (r == null || r === n.position) && (n.position = c + y), s && await this.notifyChange({ path: n.path, type: h.Changed, isDirectory: !1 }), y;
|
|
865
|
+
} catch (c) {
|
|
866
|
+
throw g("write", t, n.path, c);
|
|
866
867
|
}
|
|
867
868
|
}
|
|
868
869
|
/**
|
|
@@ -904,13 +905,13 @@ class k {
|
|
|
904
905
|
* ```
|
|
905
906
|
*/
|
|
906
907
|
async ftruncate(t, e = 0) {
|
|
907
|
-
const
|
|
908
|
+
const a = this._getFileDescriptor(t);
|
|
908
909
|
if (e < 0 || !Number.isInteger(e))
|
|
909
|
-
throw new
|
|
910
|
+
throw new E("argument", "Invalid size");
|
|
910
911
|
try {
|
|
911
|
-
|
|
912
|
-
} catch (
|
|
913
|
-
throw
|
|
912
|
+
a.syncHandle.truncate(e), a.syncHandle.flush(), a.position > e && (a.position = e), await this.notifyChange({ path: a.path, type: h.Changed, isDirectory: !1 });
|
|
913
|
+
} catch (i) {
|
|
914
|
+
throw g("truncate", t, a.path, i);
|
|
914
915
|
}
|
|
915
916
|
}
|
|
916
917
|
/**
|
|
@@ -931,8 +932,8 @@ class k {
|
|
|
931
932
|
const e = this._getFileDescriptor(t);
|
|
932
933
|
try {
|
|
933
934
|
e.syncHandle.flush();
|
|
934
|
-
} catch (
|
|
935
|
-
throw
|
|
935
|
+
} catch (a) {
|
|
936
|
+
throw g("sync", t, e.path, a);
|
|
936
937
|
}
|
|
937
938
|
}
|
|
938
939
|
/**
|
|
@@ -978,18 +979,18 @@ class k {
|
|
|
978
979
|
async createIndex(t) {
|
|
979
980
|
await this.mount();
|
|
980
981
|
try {
|
|
981
|
-
for (const [e,
|
|
982
|
-
const
|
|
982
|
+
for (const [e, a] of t) {
|
|
983
|
+
const i = F(e);
|
|
983
984
|
let r;
|
|
984
|
-
|
|
985
|
+
a instanceof Blob ? r = await L(a) : typeof a == "string" ? r = new TextEncoder().encode(a) : r = a, await this.writeFile(i, r);
|
|
985
986
|
}
|
|
986
987
|
} catch (e) {
|
|
987
|
-
throw e instanceof
|
|
988
|
+
throw e instanceof f ? e : l(e);
|
|
988
989
|
}
|
|
989
990
|
}
|
|
990
991
|
}
|
|
991
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
992
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && k(new j());
|
|
992
993
|
export {
|
|
993
|
-
|
|
994
|
+
j as OPFSWorker
|
|
994
995
|
};
|
|
995
996
|
//# sourceMappingURL=raw.js.map
|