opfs-worker 1.2.2 → 1.2.4
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-BEh95XuP.js.map +1 -0
- package/dist/assets/worker-CS9nvwsF.js.map +1 -0
- package/dist/assets/worker-Dy3EFYv_.js.map +1 -0
- package/dist/facade.d.ts +50 -14
- package/dist/facade.d.ts.map +1 -1
- package/dist/helpers-04x7UBul.cjs +4 -0
- package/dist/helpers-04x7UBul.cjs.map +1 -0
- package/dist/{helpers-CkNHswLp.js → helpers-BXhw_-Ar.js} +112 -110
- package/dist/helpers-BXhw_-Ar.js.map +1 -0
- package/dist/helpers-BwklIUit.js +1329 -0
- package/dist/helpers-BwklIUit.js.map +1 -0
- package/dist/helpers-ppMRzIAJ.cjs +4 -0
- package/dist/helpers-ppMRzIAJ.cjs.map +1 -0
- package/dist/index.cjs +262 -260
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +379 -334
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +136 -134
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +11 -4
- package/dist/types.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-BuPeqKqw.js.map +0 -1
- package/dist/helpers-CkNHswLp.js.map +0 -1
- package/dist/helpers-TAynP0fb.cjs +0 -4
- package/dist/helpers-TAynP0fb.cjs.map +0 -1
package/dist/raw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expose as
|
|
2
|
-
import { O as o, o as
|
|
3
|
-
class
|
|
1
|
+
import { expose as A, transfer as m } from "comlink";
|
|
2
|
+
import { O as o, o as g, g as C, n as F, s as p, P as b, w as f, F as E, j as H, W as l, h as v, k as D, u as $, y as T, r as S, l as O, C as N, A as I, z as x, B as P, f as u, x as _ } from "./helpers-BwklIUit.js";
|
|
3
|
+
class k {
|
|
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 _ {
|
|
|
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 */
|
|
@@ -44,12 +44,12 @@ class _ {
|
|
|
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) => g(e, r.pattern) && r.include.some((s) => s && g(e, s)) && !r.exclude.some((s) => s && g(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 _ {
|
|
|
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 _ {
|
|
|
76
76
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
77
77
|
*/
|
|
78
78
|
constructor(t) {
|
|
79
|
-
|
|
79
|
+
C(), t && this.setOptions(t);
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* Initialize the file system within a given directory
|
|
@@ -101,12 +101,12 @@ class _ {
|
|
|
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 o("Failed to initialize OPFS", "INIT_FAILED", t, i));
|
|
110
110
|
} finally {
|
|
111
111
|
this.mountingPromise = null;
|
|
112
112
|
}
|
|
@@ -123,7 +123,7 @@ class _ {
|
|
|
123
123
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
124
124
|
*/
|
|
125
125
|
async setOptions(t) {
|
|
126
|
-
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), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root =
|
|
126
|
+
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), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = F(t.root), this.options.namespace || (this.options.namespace = `opfs-worker:${this.options.root}`), await this.mount());
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
129
|
* Get a directory handle from a path
|
|
@@ -143,10 +143,10 @@ class _ {
|
|
|
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 : p(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 _ {
|
|
|
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 = p(t);
|
|
174
|
+
if (i.length === 0)
|
|
175
|
+
throw new b("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 _ {
|
|
|
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 _ {
|
|
|
239
239
|
async readFile(t) {
|
|
240
240
|
await this.mount();
|
|
241
241
|
try {
|
|
242
|
-
return await
|
|
242
|
+
return await f(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), m(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 E(t, e);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
@@ -276,15 +276,15 @@ class _ {
|
|
|
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 f(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 ? l.Changed : l.Added, isDirectory: !1 });
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
@@ -311,16 +311,16 @@ class _ {
|
|
|
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 f(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: l.Changed, isDirectory: !1 });
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
/**
|
|
@@ -346,22 +346,22 @@ class _ {
|
|
|
346
346
|
*/
|
|
347
347
|
async mkdir(t, e) {
|
|
348
348
|
await this.mount();
|
|
349
|
-
const
|
|
349
|
+
const a = e?.recursive ?? !1, i = p(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:
|
|
354
|
+
r = await r.getDirectoryHandle(n, { create: a || s === i.length - 1 });
|
|
355
355
|
} catch (c) {
|
|
356
356
|
throw c.name === "NotFoundError" ? new o(
|
|
357
|
-
`Parent directory does not exist: ${
|
|
357
|
+
`Parent directory does not exist: ${H(i.slice(0, s + 1))}`,
|
|
358
358
|
"ENOENT",
|
|
359
359
|
void 0,
|
|
360
360
|
c
|
|
361
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);
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
|
-
await this.notifyChange({ path: t, type:
|
|
364
|
+
await this.notifyChange({ path: t, type: l.Added, isDirectory: !0 });
|
|
365
365
|
}
|
|
366
366
|
/**
|
|
367
367
|
* Get file or directory statistics
|
|
@@ -395,9 +395,9 @@ class _ {
|
|
|
395
395
|
isFile: !1,
|
|
396
396
|
isDirectory: !0
|
|
397
397
|
};
|
|
398
|
-
const e =
|
|
398
|
+
const e = v(t), a = await this.getDirectoryHandle(D(t), !1), i = this.options.hashAlgorithm;
|
|
399
399
|
try {
|
|
400
|
-
const s = await (await
|
|
400
|
+
const s = await (await a.getFileHandle(e, { create: !1 })).getFile(), n = {
|
|
401
401
|
kind: "file",
|
|
402
402
|
size: s.size,
|
|
403
403
|
mtime: new Date(s.lastModified).toISOString(),
|
|
@@ -405,9 +405,11 @@ class _ {
|
|
|
405
405
|
isFile: !0,
|
|
406
406
|
isDirectory: !1
|
|
407
407
|
};
|
|
408
|
-
if (
|
|
408
|
+
if (i === "etag")
|
|
409
|
+
n.hash = `${s.lastModified.toString(36)}-${s.size.toString(36)}`;
|
|
410
|
+
else if (typeof i == "string")
|
|
409
411
|
try {
|
|
410
|
-
const c = await
|
|
412
|
+
const c = await $(s, i, this.options.maxFileSize);
|
|
411
413
|
n.hash = c;
|
|
412
414
|
} catch (c) {
|
|
413
415
|
console.warn(`Failed to calculate hash for ${t}:`, c);
|
|
@@ -418,7 +420,7 @@ class _ {
|
|
|
418
420
|
throw new o("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
419
421
|
}
|
|
420
422
|
try {
|
|
421
|
-
return await
|
|
423
|
+
return await a.getDirectoryHandle(e, { create: !1 }), {
|
|
422
424
|
kind: "directory",
|
|
423
425
|
size: 0,
|
|
424
426
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -450,17 +452,17 @@ class _ {
|
|
|
450
452
|
*/
|
|
451
453
|
async readDir(t) {
|
|
452
454
|
await this.mount();
|
|
453
|
-
const e = await this.getDirectoryHandle(t, !1),
|
|
454
|
-
for await (const [
|
|
455
|
+
const e = await this.getDirectoryHandle(t, !1), a = [];
|
|
456
|
+
for await (const [i, r] of e.entries()) {
|
|
455
457
|
const s = r.kind === "file";
|
|
456
|
-
|
|
457
|
-
name:
|
|
458
|
+
a.push({
|
|
459
|
+
name: i,
|
|
458
460
|
kind: r.kind,
|
|
459
461
|
isFile: s,
|
|
460
462
|
isDirectory: !s
|
|
461
463
|
});
|
|
462
464
|
}
|
|
463
|
-
return
|
|
465
|
+
return a;
|
|
464
466
|
}
|
|
465
467
|
/**
|
|
466
468
|
* Check if a file or directory exists
|
|
@@ -479,23 +481,23 @@ class _ {
|
|
|
479
481
|
async exists(t) {
|
|
480
482
|
if (await this.mount(), t === "/")
|
|
481
483
|
return !0;
|
|
482
|
-
const e =
|
|
483
|
-
let
|
|
484
|
+
const e = v(t);
|
|
485
|
+
let a = null;
|
|
484
486
|
try {
|
|
485
|
-
|
|
486
|
-
} catch (
|
|
487
|
-
if (
|
|
488
|
-
throw
|
|
487
|
+
a = await this.getDirectoryHandle(D(t), !1);
|
|
488
|
+
} catch (i) {
|
|
489
|
+
if (a = null, i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
490
|
+
throw i;
|
|
489
491
|
}
|
|
490
|
-
if (!
|
|
492
|
+
if (!a || !e)
|
|
491
493
|
return !1;
|
|
492
494
|
try {
|
|
493
|
-
return await
|
|
494
|
-
} catch (
|
|
495
|
-
if (
|
|
496
|
-
throw
|
|
495
|
+
return await a.getFileHandle(e, { create: !1 }), !0;
|
|
496
|
+
} catch (i) {
|
|
497
|
+
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
498
|
+
throw i;
|
|
497
499
|
try {
|
|
498
|
-
return await
|
|
500
|
+
return await a.getDirectoryHandle(e, { create: !1 }), !0;
|
|
499
501
|
} catch (r) {
|
|
500
502
|
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
501
503
|
throw r;
|
|
@@ -526,11 +528,11 @@ class _ {
|
|
|
526
528
|
await this.mount();
|
|
527
529
|
try {
|
|
528
530
|
const e = await this.readDir(t);
|
|
529
|
-
for (const
|
|
530
|
-
const
|
|
531
|
-
await this.remove(
|
|
531
|
+
for (const a of e) {
|
|
532
|
+
const i = `${t === "/" ? "" : t}/${a.name}`;
|
|
533
|
+
await this.remove(i, { recursive: !0 });
|
|
532
534
|
}
|
|
533
|
-
await this.notifyChange({ path: t, type:
|
|
535
|
+
await this.notifyChange({ path: t, type: l.Changed, isDirectory: !0 });
|
|
534
536
|
} catch (e) {
|
|
535
537
|
throw e instanceof o ? e : new o(`Failed to clear directory: ${t}`, "CLEAR_FAILED", void 0, e);
|
|
536
538
|
}
|
|
@@ -562,8 +564,8 @@ class _ {
|
|
|
562
564
|
async remove(t, e) {
|
|
563
565
|
if (await this.mount(), t === "/")
|
|
564
566
|
throw new o("Cannot remove root directory", "EROOT");
|
|
565
|
-
const { recursive:
|
|
566
|
-
await
|
|
567
|
+
const { recursive: a = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(D(t), !1), s = await this.stat(t);
|
|
568
|
+
await T(r, t, { recursive: a, force: i }), await this.notifyChange({ path: t, type: l.Removed, isDirectory: s.isDirectory });
|
|
567
569
|
}
|
|
568
570
|
/**
|
|
569
571
|
* Resolve a path to an absolute path
|
|
@@ -586,9 +588,9 @@ class _ {
|
|
|
586
588
|
async realpath(t) {
|
|
587
589
|
await this.mount();
|
|
588
590
|
try {
|
|
589
|
-
const e =
|
|
591
|
+
const e = S(t);
|
|
590
592
|
if (!await this.exists(e))
|
|
591
|
-
throw new
|
|
593
|
+
throw new E(e);
|
|
592
594
|
return e;
|
|
593
595
|
} catch (e) {
|
|
594
596
|
throw e instanceof o ? e : new o(`Failed to resolve path: ${t}`, "REALPATH_FAILED", void 0, e);
|
|
@@ -616,15 +618,15 @@ class _ {
|
|
|
616
618
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
617
619
|
* ```
|
|
618
620
|
*/
|
|
619
|
-
async rename(t, e,
|
|
621
|
+
async rename(t, e, a) {
|
|
620
622
|
await this.mount();
|
|
621
623
|
try {
|
|
622
|
-
const
|
|
623
|
-
if (await this.exists(e) && !
|
|
624
|
+
const i = a?.overwrite ?? !1, r = await this.stat(t);
|
|
625
|
+
if (await this.exists(e) && !i)
|
|
624
626
|
throw new o(`Destination already exists: ${e}`, "EEXIST", void 0);
|
|
625
|
-
await this.copy(t, e, { recursive: !0, overwrite:
|
|
626
|
-
} catch (
|
|
627
|
-
throw
|
|
627
|
+
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: l.Removed, isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: l.Added, isDirectory: r.isDirectory });
|
|
628
|
+
} catch (i) {
|
|
629
|
+
throw i instanceof o ? i : new o(`Failed to rename from ${t} to ${e}`, "RENAME_FAILED", void 0, i);
|
|
628
630
|
}
|
|
629
631
|
}
|
|
630
632
|
/**
|
|
@@ -652,10 +654,10 @@ class _ {
|
|
|
652
654
|
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
653
655
|
* ```
|
|
654
656
|
*/
|
|
655
|
-
async copy(t, e,
|
|
657
|
+
async copy(t, e, a) {
|
|
656
658
|
await this.mount();
|
|
657
659
|
try {
|
|
658
|
-
const
|
|
660
|
+
const i = a?.recursive ?? !1, r = a?.overwrite ?? !0;
|
|
659
661
|
if (!await this.exists(t))
|
|
660
662
|
throw new o(`Source does not exist: ${t}`, "ENOENT", void 0);
|
|
661
663
|
if (await this.exists(e) && !r)
|
|
@@ -664,17 +666,17 @@ class _ {
|
|
|
664
666
|
const h = await this.readFile(t);
|
|
665
667
|
await this.writeFile(e, h);
|
|
666
668
|
} else {
|
|
667
|
-
if (!
|
|
669
|
+
if (!i)
|
|
668
670
|
throw new o(`Cannot copy directory without recursive option: ${t}`, "EISDIR", void 0);
|
|
669
671
|
await this.mkdir(e, { recursive: !0 });
|
|
670
672
|
const h = await this.readDir(t);
|
|
671
|
-
for (const
|
|
672
|
-
const
|
|
673
|
-
await this.copy(
|
|
673
|
+
for (const w of h) {
|
|
674
|
+
const d = `${t}/${w.name}`, y = `${e}/${w.name}`;
|
|
675
|
+
await this.copy(d, y, { recursive: !0, overwrite: r });
|
|
674
676
|
}
|
|
675
677
|
}
|
|
676
|
-
} catch (
|
|
677
|
-
throw
|
|
678
|
+
} catch (i) {
|
|
679
|
+
throw i instanceof o ? i : new o(`Failed to copy from ${t} to ${e}`, "CP_FAILED", void 0, i);
|
|
678
680
|
}
|
|
679
681
|
}
|
|
680
682
|
/**
|
|
@@ -705,12 +707,12 @@ class _ {
|
|
|
705
707
|
async watch(t, e) {
|
|
706
708
|
if (!this.options.broadcastChannel)
|
|
707
709
|
throw new o("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
708
|
-
const
|
|
709
|
-
pattern:
|
|
710
|
+
const a = {
|
|
711
|
+
pattern: O(t, e?.recursive ?? !0),
|
|
710
712
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
711
713
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
712
714
|
};
|
|
713
|
-
this.watchers.set(t,
|
|
715
|
+
this.watchers.set(t, a);
|
|
714
716
|
}
|
|
715
717
|
/**
|
|
716
718
|
* Stop watching a previously watched path
|
|
@@ -747,13 +749,13 @@ class _ {
|
|
|
747
749
|
*/
|
|
748
750
|
async open(t, e) {
|
|
749
751
|
await this.mount();
|
|
750
|
-
const { create:
|
|
752
|
+
const { create: a = !1, exclusive: i = !1, truncate: r = !1 } = e || {}, s = F(S(t));
|
|
751
753
|
try {
|
|
752
|
-
return
|
|
754
|
+
return a && i ? await f(s, "exclusive", async () => {
|
|
753
755
|
if (await this.exists(s))
|
|
754
756
|
throw new o(`File already exists: ${s}`, "EEXIST", s);
|
|
755
|
-
return this._openFile(s,
|
|
756
|
-
}) : await this._openFile(s,
|
|
757
|
+
return this._openFile(s, a, r);
|
|
758
|
+
}) : await this._openFile(s, a, r);
|
|
757
759
|
} catch (n) {
|
|
758
760
|
throw n instanceof o ? n : new o(`Failed to open file: ${s}`, "OPEN_FAILED", s, n);
|
|
759
761
|
}
|
|
@@ -762,19 +764,19 @@ class _ {
|
|
|
762
764
|
* Internal method to open a file (without locking)
|
|
763
765
|
* @private
|
|
764
766
|
*/
|
|
765
|
-
async _openFile(t, e,
|
|
766
|
-
const
|
|
767
|
+
async _openFile(t, e, a) {
|
|
768
|
+
const i = await this.getFileHandle(t, e);
|
|
767
769
|
try {
|
|
768
|
-
await
|
|
770
|
+
await i.getFile();
|
|
769
771
|
} catch (n) {
|
|
770
772
|
throw n.name === "TypeMismatchError" ? new o(`Is a directory: ${t}`, "EISDIR", t) : n;
|
|
771
773
|
}
|
|
772
|
-
const r = await
|
|
773
|
-
|
|
774
|
+
const r = await N(i, t);
|
|
775
|
+
a && (r.truncate(0), r.flush());
|
|
774
776
|
const s = this.nextFd++;
|
|
775
777
|
return this.openFiles.set(s, {
|
|
776
778
|
path: t,
|
|
777
|
-
fileHandle:
|
|
779
|
+
fileHandle: i,
|
|
778
780
|
syncHandle: r,
|
|
779
781
|
position: 0
|
|
780
782
|
}), s;
|
|
@@ -795,7 +797,7 @@ class _ {
|
|
|
795
797
|
*/
|
|
796
798
|
async close(t) {
|
|
797
799
|
const e = this._getFileDescriptor(t);
|
|
798
|
-
|
|
800
|
+
I(t, e.syncHandle, e.path), this.openFiles.delete(t);
|
|
799
801
|
}
|
|
800
802
|
/**
|
|
801
803
|
* Read data from a file descriptor
|
|
@@ -821,17 +823,17 @@ class _ {
|
|
|
821
823
|
* await fs.close(fd);
|
|
822
824
|
* ```
|
|
823
825
|
*/
|
|
824
|
-
async read(t, e,
|
|
826
|
+
async read(t, e, a, i, r) {
|
|
825
827
|
const s = this._getFileDescriptor(t);
|
|
826
|
-
|
|
828
|
+
x(e.length, a, i, r);
|
|
827
829
|
try {
|
|
828
|
-
const n = r ?? s.position, c = s.syncHandle.getSize(), { isEOF: h, actualLength:
|
|
830
|
+
const n = r ?? s.position, c = s.syncHandle.getSize(), { isEOF: h, actualLength: w } = P(n, i, c);
|
|
829
831
|
if (h)
|
|
830
|
-
return
|
|
831
|
-
const
|
|
832
|
-
return r == null && (s.position = n +
|
|
832
|
+
return m({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
833
|
+
const d = e.subarray(a, a + w), y = s.syncHandle.read(d, { at: n });
|
|
834
|
+
return r == null && (s.position = n + y), m({ bytesRead: y, buffer: e }, [e.buffer]);
|
|
833
835
|
} catch (n) {
|
|
834
|
-
throw
|
|
836
|
+
throw u("read", t, s.path, n);
|
|
835
837
|
}
|
|
836
838
|
}
|
|
837
839
|
/**
|
|
@@ -855,14 +857,14 @@ class _ {
|
|
|
855
857
|
* await fs.close(fd);
|
|
856
858
|
* ```
|
|
857
859
|
*/
|
|
858
|
-
async write(t, e,
|
|
859
|
-
const n = this._getFileDescriptor(t), c =
|
|
860
|
-
|
|
860
|
+
async write(t, e, a = 0, i, r, s = !0) {
|
|
861
|
+
const n = this._getFileDescriptor(t), c = i ?? e.length - a;
|
|
862
|
+
x(e.length, a, c, r);
|
|
861
863
|
try {
|
|
862
|
-
const h = r ?? n.position,
|
|
863
|
-
return (r == null || r === n.position) && (n.position = h +
|
|
864
|
+
const h = r ?? n.position, w = e.subarray(a, a + c), d = n.syncHandle.write(w, { at: h });
|
|
865
|
+
return (r == null || r === n.position) && (n.position = h + d), s && await this.notifyChange({ path: n.path, type: l.Changed, isDirectory: !1 }), d;
|
|
864
866
|
} catch (h) {
|
|
865
|
-
throw
|
|
867
|
+
throw u("write", t, n.path, h);
|
|
866
868
|
}
|
|
867
869
|
}
|
|
868
870
|
/**
|
|
@@ -904,13 +906,13 @@ class _ {
|
|
|
904
906
|
* ```
|
|
905
907
|
*/
|
|
906
908
|
async ftruncate(t, e = 0) {
|
|
907
|
-
const
|
|
909
|
+
const a = this._getFileDescriptor(t);
|
|
908
910
|
if (e < 0 || !Number.isInteger(e))
|
|
909
911
|
throw new o("Invalid size", "EINVAL");
|
|
910
912
|
try {
|
|
911
|
-
|
|
912
|
-
} catch (
|
|
913
|
-
throw
|
|
913
|
+
a.syncHandle.truncate(e), a.syncHandle.flush(), a.position > e && (a.position = e), await this.notifyChange({ path: a.path, type: l.Changed, isDirectory: !1 });
|
|
914
|
+
} catch (i) {
|
|
915
|
+
throw u("truncate", t, a.path, i);
|
|
914
916
|
}
|
|
915
917
|
}
|
|
916
918
|
/**
|
|
@@ -931,8 +933,8 @@ class _ {
|
|
|
931
933
|
const e = this._getFileDescriptor(t);
|
|
932
934
|
try {
|
|
933
935
|
e.syncHandle.flush();
|
|
934
|
-
} catch (
|
|
935
|
-
throw
|
|
936
|
+
} catch (a) {
|
|
937
|
+
throw u("sync", t, e.path, a);
|
|
936
938
|
}
|
|
937
939
|
}
|
|
938
940
|
/**
|
|
@@ -944,7 +946,7 @@ class _ {
|
|
|
944
946
|
dispose() {
|
|
945
947
|
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
946
948
|
for (const [t, e] of this.openFiles)
|
|
947
|
-
|
|
949
|
+
I(t, e.syncHandle, e.path);
|
|
948
950
|
this.openFiles.clear(), this.nextFd = 1;
|
|
949
951
|
}
|
|
950
952
|
/**
|
|
@@ -978,18 +980,18 @@ class _ {
|
|
|
978
980
|
async createIndex(t) {
|
|
979
981
|
await this.mount();
|
|
980
982
|
try {
|
|
981
|
-
for (const [e,
|
|
982
|
-
const
|
|
983
|
+
for (const [e, a] of t) {
|
|
984
|
+
const i = F(e);
|
|
983
985
|
let r;
|
|
984
|
-
|
|
986
|
+
a instanceof Blob ? r = await _(a) : typeof a == "string" ? r = new TextEncoder().encode(a) : r = a, await this.writeFile(i, r);
|
|
985
987
|
}
|
|
986
988
|
} catch (e) {
|
|
987
989
|
throw e instanceof o ? e : new o("Failed to sync file system", "SYNC_FAILED", void 0, e);
|
|
988
990
|
}
|
|
989
991
|
}
|
|
990
992
|
}
|
|
991
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
993
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && A(new k());
|
|
992
994
|
export {
|
|
993
|
-
|
|
995
|
+
k as OPFSWorker
|
|
994
996
|
};
|
|
995
997
|
//# sourceMappingURL=raw.js.map
|