opfs-worker 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{worker-CLvhwwfc.js.map → worker-BuPeqKqw.js.map} +1 -1
- package/dist/facade.d.ts +1 -3
- package/dist/facade.d.ts.map +1 -1
- package/dist/index.cjs +71 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +76 -77
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +121 -122
- package/dist/raw.js.map +1 -1
- package/dist/worker.d.ts +1 -3
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/raw.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expose as x, transfer as u } from "comlink";
|
|
2
|
-
import { O as o, o as m, g as A, n as g, s as F, P as C, w as
|
|
2
|
+
import { O as o, o as m, g as A, n as g, s as F, P as C, w as y, F as D, j as b, h as E, k as p, u as H, y as $, r as v, l as T, C as O, A as S, z as I, B as N, f, x as P } from "./helpers-CkNHswLp.js";
|
|
3
3
|
class _ {
|
|
4
4
|
/** Root directory handle for the file system */
|
|
5
5
|
root;
|
|
@@ -46,10 +46,10 @@ class _ {
|
|
|
46
46
|
const e = t.path;
|
|
47
47
|
if (![...this.watchers.values()].some((r) => m(e, r.pattern) && r.include.some((s) => s && m(e, s)) && !r.exclude.some((s) => s && m(e, s))))
|
|
48
48
|
return;
|
|
49
|
-
let
|
|
49
|
+
let a;
|
|
50
50
|
if (this.options.hashAlgorithm)
|
|
51
51
|
try {
|
|
52
|
-
|
|
52
|
+
a = (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
|
+
...a && { hash: a }
|
|
62
62
|
};
|
|
63
63
|
this.broadcastChannel.postMessage(r);
|
|
64
64
|
} catch (r) {
|
|
@@ -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, i) => {
|
|
105
105
|
try {
|
|
106
|
-
const
|
|
107
|
-
this.root = t === "/" ?
|
|
108
|
-
} catch (
|
|
109
|
-
|
|
106
|
+
const a = await navigator.storage.getDirectory();
|
|
107
|
+
this.root = t === "/" ? a : await this.getDirectoryHandle(t, !0, a), e(!0);
|
|
108
|
+
} catch (a) {
|
|
109
|
+
i(new o("Failed to initialize OPFS", "INIT_FAILED", t, a));
|
|
110
110
|
} finally {
|
|
111
111
|
this.mountingPromise = null;
|
|
112
112
|
}
|
|
@@ -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, i = this.root) {
|
|
147
|
+
const a = Array.isArray(t) ? t : F(t);
|
|
148
|
+
let r = i;
|
|
149
|
+
for (const s of a)
|
|
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 (
|
|
172
|
+
async getFileHandle(t, e = !1, i = this.root) {
|
|
173
|
+
const a = F(t);
|
|
174
|
+
if (a.length === 0)
|
|
175
175
|
throw new C("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
176
|
-
const r =
|
|
177
|
-
return (await this.getDirectoryHandle(
|
|
176
|
+
const r = a.pop();
|
|
177
|
+
return (await this.getDirectoryHandle(a, e, i)).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 (i) => {
|
|
200
|
+
const a = await this.readDir(i);
|
|
201
|
+
for (const r of a) {
|
|
202
|
+
const s = `${i === "/" ? "" : i}/${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,11 +239,11 @@ class _ {
|
|
|
239
239
|
async readFile(t) {
|
|
240
240
|
await this.mount();
|
|
241
241
|
try {
|
|
242
|
-
return await
|
|
242
|
+
return await y(t, "shared", async () => {
|
|
243
243
|
const e = await this.open(t);
|
|
244
244
|
try {
|
|
245
|
-
const { size:
|
|
246
|
-
return
|
|
245
|
+
const { size: i } = await this.fstat(e), a = new Uint8Array(i);
|
|
246
|
+
return i > 0 && await this.read(e, a, 0, i, 0), u(a, [a.buffer]);
|
|
247
247
|
} finally {
|
|
248
248
|
await this.close(e);
|
|
249
249
|
}
|
|
@@ -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 i = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
280
|
+
await y(t, "exclusive", async () => {
|
|
281
|
+
const a = 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, i, 0, i.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: a ? "changed" : "added", isDirectory: !1 });
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
@@ -311,14 +311,14 @@ class _ {
|
|
|
311
311
|
*/
|
|
312
312
|
async appendFile(t, e) {
|
|
313
313
|
await this.mount();
|
|
314
|
-
const
|
|
315
|
-
await
|
|
316
|
-
const
|
|
314
|
+
const i = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
315
|
+
await y(t, "exclusive", async () => {
|
|
316
|
+
const a = 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(a);
|
|
319
|
+
await this.write(a, i, 0, i.length, r, !1), await this.fsync(a);
|
|
320
320
|
} finally {
|
|
321
|
-
await this.close(
|
|
321
|
+
await this.close(a);
|
|
322
322
|
}
|
|
323
323
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
324
324
|
});
|
|
@@ -346,15 +346,15 @@ class _ {
|
|
|
346
346
|
*/
|
|
347
347
|
async mkdir(t, e) {
|
|
348
348
|
await this.mount();
|
|
349
|
-
const
|
|
349
|
+
const i = e?.recursive ?? !1, a = F(t);
|
|
350
350
|
let r = this.root;
|
|
351
|
-
for (let s = 0; s <
|
|
352
|
-
const n =
|
|
351
|
+
for (let s = 0; s < a.length; s++) {
|
|
352
|
+
const n = a[s];
|
|
353
353
|
try {
|
|
354
|
-
r = await r.getDirectoryHandle(n, { create:
|
|
354
|
+
r = await r.getDirectoryHandle(n, { create: i || s === a.length - 1 });
|
|
355
355
|
} catch (c) {
|
|
356
356
|
throw c.name === "NotFoundError" ? new o(
|
|
357
|
-
`Parent directory does not exist: ${b(
|
|
357
|
+
`Parent directory does not exist: ${b(a.slice(0, s + 1))}`,
|
|
358
358
|
"ENOENT",
|
|
359
359
|
void 0,
|
|
360
360
|
c
|
|
@@ -395,9 +395,9 @@ class _ {
|
|
|
395
395
|
isFile: !1,
|
|
396
396
|
isDirectory: !0
|
|
397
397
|
};
|
|
398
|
-
const e = E(t),
|
|
398
|
+
const e = E(t), i = await this.getDirectoryHandle(p(t), !1), a = this.options.hashAlgorithm !== null;
|
|
399
399
|
try {
|
|
400
|
-
const s = await (await
|
|
400
|
+
const s = await (await i.getFileHandle(e, { create: !1 })).getFile(), n = {
|
|
401
401
|
kind: "file",
|
|
402
402
|
size: s.size,
|
|
403
403
|
mtime: new Date(s.lastModified).toISOString(),
|
|
@@ -405,7 +405,7 @@ class _ {
|
|
|
405
405
|
isFile: !0,
|
|
406
406
|
isDirectory: !1
|
|
407
407
|
};
|
|
408
|
-
if (
|
|
408
|
+
if (a && this.options.hashAlgorithm)
|
|
409
409
|
try {
|
|
410
410
|
const c = await H(s, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
411
411
|
n.hash = c;
|
|
@@ -418,7 +418,7 @@ class _ {
|
|
|
418
418
|
throw new o("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
419
419
|
}
|
|
420
420
|
try {
|
|
421
|
-
return await
|
|
421
|
+
return await i.getDirectoryHandle(e, { create: !1 }), {
|
|
422
422
|
kind: "directory",
|
|
423
423
|
size: 0,
|
|
424
424
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -450,17 +450,17 @@ class _ {
|
|
|
450
450
|
*/
|
|
451
451
|
async readDir(t) {
|
|
452
452
|
await this.mount();
|
|
453
|
-
const e = await this.getDirectoryHandle(t, !1),
|
|
454
|
-
for await (const [
|
|
453
|
+
const e = await this.getDirectoryHandle(t, !1), i = [];
|
|
454
|
+
for await (const [a, r] of e.entries()) {
|
|
455
455
|
const s = r.kind === "file";
|
|
456
|
-
|
|
457
|
-
name:
|
|
456
|
+
i.push({
|
|
457
|
+
name: a,
|
|
458
458
|
kind: r.kind,
|
|
459
459
|
isFile: s,
|
|
460
460
|
isDirectory: !s
|
|
461
461
|
});
|
|
462
462
|
}
|
|
463
|
-
return
|
|
463
|
+
return i;
|
|
464
464
|
}
|
|
465
465
|
/**
|
|
466
466
|
* Check if a file or directory exists
|
|
@@ -480,22 +480,22 @@ class _ {
|
|
|
480
480
|
if (await this.mount(), t === "/")
|
|
481
481
|
return !0;
|
|
482
482
|
const e = E(t);
|
|
483
|
-
let
|
|
483
|
+
let i = null;
|
|
484
484
|
try {
|
|
485
|
-
|
|
486
|
-
} catch (
|
|
487
|
-
if (
|
|
488
|
-
throw
|
|
485
|
+
i = await this.getDirectoryHandle(p(t), !1);
|
|
486
|
+
} catch (a) {
|
|
487
|
+
if (i = null, a.name !== "NotFoundError" && a.name !== "TypeMismatchError")
|
|
488
|
+
throw a;
|
|
489
489
|
}
|
|
490
|
-
if (!
|
|
490
|
+
if (!i || !e)
|
|
491
491
|
return !1;
|
|
492
492
|
try {
|
|
493
|
-
return await
|
|
494
|
-
} catch (
|
|
495
|
-
if (
|
|
496
|
-
throw
|
|
493
|
+
return await i.getFileHandle(e, { create: !1 }), !0;
|
|
494
|
+
} catch (a) {
|
|
495
|
+
if (a.name !== "NotFoundError" && a.name !== "TypeMismatchError")
|
|
496
|
+
throw a;
|
|
497
497
|
try {
|
|
498
|
-
return await
|
|
498
|
+
return await i.getDirectoryHandle(e, { create: !1 }), !0;
|
|
499
499
|
} catch (r) {
|
|
500
500
|
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
501
501
|
throw r;
|
|
@@ -526,9 +526,9 @@ class _ {
|
|
|
526
526
|
await this.mount();
|
|
527
527
|
try {
|
|
528
528
|
const e = await this.readDir(t);
|
|
529
|
-
for (const
|
|
530
|
-
const
|
|
531
|
-
await this.remove(
|
|
529
|
+
for (const i of e) {
|
|
530
|
+
const a = `${t === "/" ? "" : t}/${i.name}`;
|
|
531
|
+
await this.remove(a, { recursive: !0 });
|
|
532
532
|
}
|
|
533
533
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
534
534
|
} catch (e) {
|
|
@@ -562,8 +562,8 @@ class _ {
|
|
|
562
562
|
async remove(t, e) {
|
|
563
563
|
if (await this.mount(), t === "/")
|
|
564
564
|
throw new o("Cannot remove root directory", "EROOT");
|
|
565
|
-
const { recursive:
|
|
566
|
-
await $(r, t, { recursive:
|
|
565
|
+
const { recursive: i = !1, force: a = !1 } = e || {}, r = await this.getDirectoryHandle(p(t), !1), s = await this.stat(t);
|
|
566
|
+
await $(r, t, { recursive: i, force: a }), await this.notifyChange({ path: t, type: "removed", isDirectory: s.isDirectory });
|
|
567
567
|
}
|
|
568
568
|
/**
|
|
569
569
|
* Resolve a path to an absolute path
|
|
@@ -616,15 +616,15 @@ class _ {
|
|
|
616
616
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
617
617
|
* ```
|
|
618
618
|
*/
|
|
619
|
-
async rename(t, e,
|
|
619
|
+
async rename(t, e, i) {
|
|
620
620
|
await this.mount();
|
|
621
621
|
try {
|
|
622
|
-
const
|
|
623
|
-
if (await this.exists(e) && !
|
|
622
|
+
const a = i?.overwrite ?? !1, r = await this.stat(t);
|
|
623
|
+
if (await this.exists(e) && !a)
|
|
624
624
|
throw new o(`Destination already exists: ${e}`, "EEXIST", void 0);
|
|
625
|
-
await this.copy(t, e, { recursive: !0, overwrite:
|
|
626
|
-
} catch (
|
|
627
|
-
throw
|
|
625
|
+
await this.copy(t, e, { recursive: !0, overwrite: a }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: "added", isDirectory: r.isDirectory });
|
|
626
|
+
} catch (a) {
|
|
627
|
+
throw a instanceof o ? a : new o(`Failed to rename from ${t} to ${e}`, "RENAME_FAILED", void 0, a);
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
/**
|
|
@@ -652,29 +652,29 @@ class _ {
|
|
|
652
652
|
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
653
653
|
* ```
|
|
654
654
|
*/
|
|
655
|
-
async copy(t, e,
|
|
655
|
+
async copy(t, e, i) {
|
|
656
656
|
await this.mount();
|
|
657
657
|
try {
|
|
658
|
-
const
|
|
658
|
+
const a = i?.recursive ?? !1, r = i?.overwrite ?? !0;
|
|
659
659
|
if (!await this.exists(t))
|
|
660
660
|
throw new o(`Source does not exist: ${t}`, "ENOENT", void 0);
|
|
661
661
|
if (await this.exists(e) && !r)
|
|
662
662
|
throw new o(`Destination already exists: ${e}`, "EEXIST", void 0);
|
|
663
663
|
if ((await this.stat(t)).isFile) {
|
|
664
|
-
const
|
|
665
|
-
await this.writeFile(e,
|
|
664
|
+
const h = await this.readFile(t);
|
|
665
|
+
await this.writeFile(e, h);
|
|
666
666
|
} else {
|
|
667
|
-
if (!
|
|
667
|
+
if (!a)
|
|
668
668
|
throw new o(`Cannot copy directory without recursive option: ${t}`, "EISDIR", void 0);
|
|
669
669
|
await this.mkdir(e, { recursive: !0 });
|
|
670
|
-
const
|
|
671
|
-
for (const
|
|
672
|
-
const w = `${t}/${
|
|
673
|
-
await this.copy(w,
|
|
670
|
+
const h = await this.readDir(t);
|
|
671
|
+
for (const l of h) {
|
|
672
|
+
const w = `${t}/${l.name}`, d = `${e}/${l.name}`;
|
|
673
|
+
await this.copy(w, d, { recursive: !0, overwrite: r });
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
|
-
} catch (
|
|
677
|
-
throw
|
|
676
|
+
} catch (a) {
|
|
677
|
+
throw a instanceof o ? a : new o(`Failed to copy from ${t} to ${e}`, "CP_FAILED", void 0, a);
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
680
|
/**
|
|
@@ -705,12 +705,12 @@ class _ {
|
|
|
705
705
|
async watch(t, e) {
|
|
706
706
|
if (!this.options.broadcastChannel)
|
|
707
707
|
throw new o("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
708
|
-
const
|
|
708
|
+
const i = {
|
|
709
709
|
pattern: T(t, e?.recursive ?? !0),
|
|
710
710
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
711
711
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
712
712
|
};
|
|
713
|
-
this.watchers.set(t,
|
|
713
|
+
this.watchers.set(t, i);
|
|
714
714
|
}
|
|
715
715
|
/**
|
|
716
716
|
* Stop watching a previously watched path
|
|
@@ -747,13 +747,13 @@ class _ {
|
|
|
747
747
|
*/
|
|
748
748
|
async open(t, e) {
|
|
749
749
|
await this.mount();
|
|
750
|
-
const { create:
|
|
750
|
+
const { create: i = !1, exclusive: a = !1, truncate: r = !1 } = e || {}, s = g(v(t));
|
|
751
751
|
try {
|
|
752
|
-
return
|
|
752
|
+
return i && a ? await y(s, "exclusive", async () => {
|
|
753
753
|
if (await this.exists(s))
|
|
754
754
|
throw new o(`File already exists: ${s}`, "EEXIST", s);
|
|
755
|
-
return this._openFile(s,
|
|
756
|
-
}) : await this._openFile(s,
|
|
755
|
+
return this._openFile(s, i, r);
|
|
756
|
+
}) : await this._openFile(s, i, r);
|
|
757
757
|
} catch (n) {
|
|
758
758
|
throw n instanceof o ? n : new o(`Failed to open file: ${s}`, "OPEN_FAILED", s, n);
|
|
759
759
|
}
|
|
@@ -762,19 +762,19 @@ class _ {
|
|
|
762
762
|
* Internal method to open a file (without locking)
|
|
763
763
|
* @private
|
|
764
764
|
*/
|
|
765
|
-
async _openFile(t, e,
|
|
766
|
-
const
|
|
765
|
+
async _openFile(t, e, i) {
|
|
766
|
+
const a = await this.getFileHandle(t, e);
|
|
767
767
|
try {
|
|
768
|
-
await
|
|
768
|
+
await a.getFile();
|
|
769
769
|
} catch (n) {
|
|
770
770
|
throw n.name === "TypeMismatchError" ? new o(`Is a directory: ${t}`, "EISDIR", t) : n;
|
|
771
771
|
}
|
|
772
|
-
const r = await O(
|
|
773
|
-
|
|
772
|
+
const r = await O(a, t);
|
|
773
|
+
i && (r.truncate(0), r.flush());
|
|
774
774
|
const s = this.nextFd++;
|
|
775
775
|
return this.openFiles.set(s, {
|
|
776
776
|
path: t,
|
|
777
|
-
fileHandle:
|
|
777
|
+
fileHandle: a,
|
|
778
778
|
syncHandle: r,
|
|
779
779
|
position: 0
|
|
780
780
|
}), s;
|
|
@@ -821,15 +821,15 @@ class _ {
|
|
|
821
821
|
* await fs.close(fd);
|
|
822
822
|
* ```
|
|
823
823
|
*/
|
|
824
|
-
async read(t, e,
|
|
824
|
+
async read(t, e, i, a, r) {
|
|
825
825
|
const s = this._getFileDescriptor(t);
|
|
826
|
-
I(e.length,
|
|
826
|
+
I(e.length, i, a, r);
|
|
827
827
|
try {
|
|
828
|
-
const n = r ?? s.position, c = s.syncHandle.getSize(), { isEOF:
|
|
829
|
-
if (
|
|
828
|
+
const n = r ?? s.position, c = s.syncHandle.getSize(), { isEOF: h, actualLength: l } = N(n, a, c);
|
|
829
|
+
if (h)
|
|
830
830
|
return u({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
831
|
-
const w = e.subarray(
|
|
832
|
-
return r == null && (s.position = n +
|
|
831
|
+
const w = e.subarray(i, i + l), d = s.syncHandle.read(w, { at: n });
|
|
832
|
+
return r == null && (s.position = n + d), u({ bytesRead: d, buffer: e }, [e.buffer]);
|
|
833
833
|
} catch (n) {
|
|
834
834
|
throw f("read", t, s.path, n);
|
|
835
835
|
}
|
|
@@ -855,14 +855,14 @@ class _ {
|
|
|
855
855
|
* await fs.close(fd);
|
|
856
856
|
* ```
|
|
857
857
|
*/
|
|
858
|
-
async write(t, e,
|
|
859
|
-
const n = this._getFileDescriptor(t), c =
|
|
860
|
-
I(e.length,
|
|
858
|
+
async write(t, e, i = 0, a, r, s = !0) {
|
|
859
|
+
const n = this._getFileDescriptor(t), c = a ?? e.length - i;
|
|
860
|
+
I(e.length, i, c, r);
|
|
861
861
|
try {
|
|
862
|
-
const
|
|
863
|
-
return (r == null || r === n.position) && (n.position =
|
|
864
|
-
} catch (
|
|
865
|
-
throw f("write", t, n.path,
|
|
862
|
+
const h = r ?? n.position, l = e.subarray(i, i + c), w = n.syncHandle.write(l, { at: h });
|
|
863
|
+
return (r == null || r === n.position) && (n.position = h + w), s && await this.notifyChange({ path: n.path, type: "changed", isDirectory: !1 }), w;
|
|
864
|
+
} catch (h) {
|
|
865
|
+
throw f("write", t, n.path, h);
|
|
866
866
|
}
|
|
867
867
|
}
|
|
868
868
|
/**
|
|
@@ -904,13 +904,13 @@ class _ {
|
|
|
904
904
|
* ```
|
|
905
905
|
*/
|
|
906
906
|
async ftruncate(t, e = 0) {
|
|
907
|
-
const
|
|
907
|
+
const i = this._getFileDescriptor(t);
|
|
908
908
|
if (e < 0 || !Number.isInteger(e))
|
|
909
909
|
throw new o("Invalid size", "EINVAL");
|
|
910
910
|
try {
|
|
911
|
-
|
|
912
|
-
} catch (
|
|
913
|
-
throw f("truncate", t,
|
|
911
|
+
i.syncHandle.truncate(e), i.syncHandle.flush(), i.position > e && (i.position = e), await this.notifyChange({ path: i.path, type: "changed", isDirectory: !1 });
|
|
912
|
+
} catch (a) {
|
|
913
|
+
throw f("truncate", t, i.path, a);
|
|
914
914
|
}
|
|
915
915
|
}
|
|
916
916
|
/**
|
|
@@ -931,8 +931,8 @@ class _ {
|
|
|
931
931
|
const e = this._getFileDescriptor(t);
|
|
932
932
|
try {
|
|
933
933
|
e.syncHandle.flush();
|
|
934
|
-
} catch (
|
|
935
|
-
throw f("sync", t, e.path,
|
|
934
|
+
} catch (i) {
|
|
935
|
+
throw f("sync", t, e.path, i);
|
|
936
936
|
}
|
|
937
937
|
}
|
|
938
938
|
/**
|
|
@@ -975,17 +975,16 @@ class _ {
|
|
|
975
975
|
* await fs.sync(entries, { cleanBefore: true });
|
|
976
976
|
* ```
|
|
977
977
|
*/
|
|
978
|
-
async
|
|
978
|
+
async createIndex(t) {
|
|
979
979
|
await this.mount();
|
|
980
980
|
try {
|
|
981
|
-
(e
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
r instanceof Blob ? n = await P(r) : typeof r == "string" ? n = new TextEncoder().encode(r) : n = r, await this.writeFile(s, n);
|
|
981
|
+
for (const [e, i] of t) {
|
|
982
|
+
const a = g(e);
|
|
983
|
+
let r;
|
|
984
|
+
i instanceof Blob ? r = await P(i) : typeof i == "string" ? r = new TextEncoder().encode(i) : r = i, await this.writeFile(a, r);
|
|
986
985
|
}
|
|
987
|
-
} catch (
|
|
988
|
-
throw
|
|
986
|
+
} catch (e) {
|
|
987
|
+
throw e instanceof o ? e : new o("Failed to sync file system", "SYNC_FAILED", void 0, e);
|
|
989
988
|
}
|
|
990
989
|
}
|
|
991
990
|
}
|