opfs-worker 0.2.4 → 0.2.5
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-BL3varjN.js.map +1 -0
- package/dist/{helpers-Co-qCBmA.js → helpers-3TGPHd1h.js} +6 -5
- package/dist/{helpers-Co-qCBmA.js.map → helpers-3TGPHd1h.js.map} +1 -1
- package/dist/{helpers-hEpet7x7.cjs → helpers-DjY2OR7f.cjs} +2 -2
- package/dist/{helpers-hEpet7x7.cjs.map → helpers-DjY2OR7f.cjs.map} +1 -1
- package/dist/index.cjs +462 -466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +487 -488
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +159 -164
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +36 -54
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-DCm4BiWM.js.map +0 -1
package/dist/raw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { expose as
|
|
2
|
-
import { d as
|
|
3
|
-
class
|
|
1
|
+
import { expose as p } from "comlink";
|
|
2
|
+
import { d as S, O as n, b as l, s as w, P as g, i as I, o as v, F as f, w as F, j as T, e as y, f as u, k as M, r as A, n as d, l as $ } from "./helpers-3TGPHd1h.js";
|
|
3
|
+
class O {
|
|
4
4
|
/** Root directory handle for the file system */
|
|
5
5
|
root = null;
|
|
6
6
|
/** Watch event callback */
|
|
@@ -15,6 +15,8 @@ class N {
|
|
|
15
15
|
scanning = !1;
|
|
16
16
|
/** Promise to prevent concurrent mount operations */
|
|
17
17
|
mountingPromise = null;
|
|
18
|
+
/** Hash algorithm for file hashing (null means no hashing) */
|
|
19
|
+
hashAlgorithm = null;
|
|
18
20
|
/**
|
|
19
21
|
* Notify about internal changes to the file system
|
|
20
22
|
*
|
|
@@ -24,21 +26,34 @@ class N {
|
|
|
24
26
|
* @param path - The path that was changed
|
|
25
27
|
* @param type - The type of change (create, change, delete)
|
|
26
28
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
async notifyChange(t) {
|
|
30
|
+
if (!this.watchCallback)
|
|
31
|
+
return;
|
|
32
|
+
let e;
|
|
33
|
+
if (this.hashAlgorithm && !t.isDirectory && t.type !== "removed")
|
|
34
|
+
try {
|
|
35
|
+
const i = await this.stat(t.path);
|
|
36
|
+
i.isFile && i.hash && (e = i.hash);
|
|
37
|
+
} catch (i) {
|
|
38
|
+
console.warn(`Failed to calculate hash for ${t.path}:`, i);
|
|
39
|
+
}
|
|
40
|
+
this.watchCallback({
|
|
41
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
|
+
...t,
|
|
43
|
+
...e && { hash: e }
|
|
31
44
|
});
|
|
32
45
|
}
|
|
33
46
|
/**
|
|
34
47
|
* Creates a new OPFSFileSystem instance
|
|
35
48
|
*
|
|
36
49
|
* @param watchCallback - Optional callback for file change events
|
|
37
|
-
* @param
|
|
50
|
+
* @param options - Optional configuration options
|
|
51
|
+
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
52
|
+
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
38
53
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
39
54
|
*/
|
|
40
55
|
constructor(t, e) {
|
|
41
|
-
|
|
56
|
+
S(), t && (this.watchCallback = t), e && this.setOptions(e), this.mount("/");
|
|
42
57
|
}
|
|
43
58
|
/**
|
|
44
59
|
* Initialize the file system within a given directory
|
|
@@ -68,7 +83,7 @@ class N {
|
|
|
68
83
|
const r = await navigator.storage.getDirectory();
|
|
69
84
|
t === "/" ? this.root = r : this.root = await this.getDirectoryHandle(t, !0, r), e(!0);
|
|
70
85
|
} catch (r) {
|
|
71
|
-
console.error(r), i(new
|
|
86
|
+
console.error(r), i(new n("Failed to initialize OPFS", "INIT_FAILED"));
|
|
72
87
|
} finally {
|
|
73
88
|
this.mountingPromise = null;
|
|
74
89
|
}
|
|
@@ -78,10 +93,19 @@ class N {
|
|
|
78
93
|
* Set the watch callback for file change events
|
|
79
94
|
*
|
|
80
95
|
* @param callback - The callback function to invoke when files change
|
|
81
|
-
* @param options - Optional configuration for watching
|
|
82
96
|
*/
|
|
83
|
-
setWatchCallback(t
|
|
84
|
-
this.watchCallback = t
|
|
97
|
+
setWatchCallback(t) {
|
|
98
|
+
this.watchCallback = t;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set configuration options for the file system
|
|
102
|
+
*
|
|
103
|
+
* @param options - Configuration options to update
|
|
104
|
+
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
105
|
+
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
106
|
+
*/
|
|
107
|
+
setOptions(t) {
|
|
108
|
+
t.watchInterval !== void 0 && (this.watchInterval = t.watchInterval), t.hashAlgorithm !== void 0 && (this.hashAlgorithm = t.hashAlgorithm);
|
|
85
109
|
}
|
|
86
110
|
/**
|
|
87
111
|
* Automatically mount the OPFS root if not already mounted
|
|
@@ -98,7 +122,7 @@ class N {
|
|
|
98
122
|
await this.mountingPromise;
|
|
99
123
|
return;
|
|
100
124
|
}
|
|
101
|
-
throw new
|
|
125
|
+
throw new n("OPFS not mounted", "NOT_MOUNTED");
|
|
102
126
|
}
|
|
103
127
|
}
|
|
104
128
|
/**
|
|
@@ -121,11 +145,11 @@ class N {
|
|
|
121
145
|
*/
|
|
122
146
|
async getDirectoryHandle(t, e = !1, i = this.root) {
|
|
123
147
|
if (!i)
|
|
124
|
-
throw new
|
|
125
|
-
const r = Array.isArray(t) ? t :
|
|
148
|
+
throw new l();
|
|
149
|
+
const r = Array.isArray(t) ? t : w(t);
|
|
126
150
|
let a = i;
|
|
127
|
-
for (const
|
|
128
|
-
a = await a.getDirectoryHandle(
|
|
151
|
+
for (const s of r)
|
|
152
|
+
a = await a.getDirectoryHandle(s, { create: e });
|
|
129
153
|
return a;
|
|
130
154
|
}
|
|
131
155
|
/**
|
|
@@ -149,43 +173,25 @@ class N {
|
|
|
149
173
|
*/
|
|
150
174
|
async getFileHandle(t, e = !1, i = this.root) {
|
|
151
175
|
if (!i)
|
|
152
|
-
throw new
|
|
153
|
-
const r =
|
|
176
|
+
throw new l();
|
|
177
|
+
const r = w(t);
|
|
154
178
|
if (r.length === 0)
|
|
155
|
-
throw new
|
|
179
|
+
throw new g("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
156
180
|
const a = r.pop();
|
|
157
181
|
return (await this.getDirectoryHandle(r, e, i)).getFileHandle(a, { create: e });
|
|
158
182
|
}
|
|
159
183
|
/**
|
|
160
|
-
*
|
|
184
|
+
* Get a complete index of all files and directories in the file system
|
|
161
185
|
*
|
|
162
|
-
*
|
|
163
|
-
* a Map containing
|
|
186
|
+
* This method recursively traverses the entire file system and returns
|
|
187
|
+
* a Map containing FileStat objects for every file and directory.
|
|
164
188
|
*
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
167
|
-
* @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
|
|
168
|
-
* @returns Promise that resolves to a Map of path => FileStat
|
|
169
|
-
* @throws {OPFSError} If the indexing operation fails
|
|
189
|
+
* @returns Promise that resolves to a Map of paths to FileStat objects
|
|
190
|
+
* @throws {OPFSError} If the file system is not mounted
|
|
170
191
|
*
|
|
171
192
|
* @example
|
|
172
193
|
* ```typescript
|
|
173
|
-
* // Basic index without hash
|
|
174
194
|
* const index = await fs.index();
|
|
175
|
-
*
|
|
176
|
-
* // Index with file hash
|
|
177
|
-
* const indexWithHash = await fs.index({
|
|
178
|
-
* includeHash: true,
|
|
179
|
-
* hashAlgorithm: 'SHA-1'
|
|
180
|
-
* });
|
|
181
|
-
*
|
|
182
|
-
* // Iterate through all files and directories
|
|
183
|
-
* for (const [path, stat] of index) {
|
|
184
|
-
* console.log(`${path}: ${stat.isFile ? 'file' : 'directory'} (${stat.size} bytes)`);
|
|
185
|
-
* if (stat.hash) console.log(` Hash: ${stat.hash}`);
|
|
186
|
-
* }
|
|
187
|
-
*
|
|
188
|
-
* // Get specific file stats
|
|
189
195
|
* const fileStats = index.get('/data/config.json');
|
|
190
196
|
* if (fileStats) {
|
|
191
197
|
* console.log(`File size: ${fileStats.size} bytes`);
|
|
@@ -193,35 +199,35 @@ class N {
|
|
|
193
199
|
* }
|
|
194
200
|
* ```
|
|
195
201
|
*/
|
|
196
|
-
async index(
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
for (const
|
|
200
|
-
const s = `${
|
|
202
|
+
async index() {
|
|
203
|
+
const t = /* @__PURE__ */ new Map(), e = async (i) => {
|
|
204
|
+
const r = await this.readdir(i, { withFileTypes: !0 });
|
|
205
|
+
for (const a of r) {
|
|
206
|
+
const s = `${i === "/" ? "" : i}/${a.name}`;
|
|
201
207
|
try {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
} catch (
|
|
205
|
-
console.warn(`Skipping broken entry: ${s}`,
|
|
208
|
+
const o = await this.stat(s);
|
|
209
|
+
t.set(s, o), o.isDirectory && await e(s);
|
|
210
|
+
} catch (o) {
|
|
211
|
+
console.warn(`Skipping broken entry: ${s}`, o);
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
214
|
};
|
|
209
|
-
return
|
|
215
|
+
return t.set("/", {
|
|
210
216
|
kind: "directory",
|
|
211
217
|
size: 0,
|
|
212
218
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
213
219
|
ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
214
220
|
isFile: !1,
|
|
215
221
|
isDirectory: !0
|
|
216
|
-
}), await
|
|
222
|
+
}), await e("/"), t;
|
|
217
223
|
}
|
|
218
224
|
async readFile(t, e = "utf-8") {
|
|
219
225
|
await this.ensureMounted();
|
|
220
226
|
try {
|
|
221
|
-
const i = await this.getFileHandle(t, !1), r = await
|
|
222
|
-
return e === "binary" ? r :
|
|
227
|
+
const i = await this.getFileHandle(t, !1), r = await I(i);
|
|
228
|
+
return e === "binary" ? r : v(r, e);
|
|
223
229
|
} catch (i) {
|
|
224
|
-
throw console.error(i), new
|
|
230
|
+
throw console.error(i), new f(t);
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
/**
|
|
@@ -252,7 +258,7 @@ class N {
|
|
|
252
258
|
async writeFile(t, e, i) {
|
|
253
259
|
await this.ensureMounted();
|
|
254
260
|
const r = await this.getFileHandle(t, !0);
|
|
255
|
-
await
|
|
261
|
+
await F(r, e, i, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
256
262
|
}
|
|
257
263
|
/**
|
|
258
264
|
* Append data to a file
|
|
@@ -279,7 +285,7 @@ class N {
|
|
|
279
285
|
async appendFile(t, e, i) {
|
|
280
286
|
await this.ensureMounted();
|
|
281
287
|
const r = await this.getFileHandle(t, !0);
|
|
282
|
-
await
|
|
288
|
+
await F(r, e, i, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
283
289
|
}
|
|
284
290
|
/**
|
|
285
291
|
* Create a directory
|
|
@@ -304,52 +310,45 @@ class N {
|
|
|
304
310
|
*/
|
|
305
311
|
async mkdir(t, e) {
|
|
306
312
|
if (await this.ensureMounted(), !this.root)
|
|
307
|
-
throw new
|
|
308
|
-
const i = e?.recursive ?? !1, r =
|
|
313
|
+
throw new l();
|
|
314
|
+
const i = e?.recursive ?? !1, r = w(t);
|
|
309
315
|
let a = this.root;
|
|
310
|
-
for (let
|
|
311
|
-
const
|
|
316
|
+
for (let s = 0; s < r.length; s++) {
|
|
317
|
+
const o = r[s];
|
|
312
318
|
try {
|
|
313
|
-
a = await a.getDirectoryHandle(
|
|
319
|
+
a = await a.getDirectoryHandle(o, { create: i || s === r.length - 1 });
|
|
314
320
|
} catch (c) {
|
|
315
|
-
throw c.name === "NotFoundError" ? new
|
|
316
|
-
`Parent directory does not exist: ${
|
|
321
|
+
throw c.name === "NotFoundError" ? new n(
|
|
322
|
+
`Parent directory does not exist: ${T(r.slice(0, s + 1))}`,
|
|
317
323
|
"ENOENT"
|
|
318
|
-
) : c.name === "TypeMismatchError" ? new
|
|
324
|
+
) : c.name === "TypeMismatchError" ? new n(`Path segment is not a directory: ${o}`, "ENOTDIR") : new n("Failed to create directory", "MKDIR_FAILED");
|
|
319
325
|
}
|
|
320
326
|
}
|
|
321
|
-
this.
|
|
327
|
+
await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
|
|
322
328
|
}
|
|
323
329
|
/**
|
|
324
|
-
* Get file or directory
|
|
330
|
+
* Get file or directory statistics
|
|
325
331
|
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
332
|
+
* Returns detailed information about a file or directory, including
|
|
333
|
+
* size, modification time, and optionally a hash of the file content.
|
|
328
334
|
*
|
|
329
335
|
* @param path - The path to the file or directory
|
|
330
|
-
* @
|
|
331
|
-
* @
|
|
332
|
-
* @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
|
|
333
|
-
* @returns Promise that resolves to file/directory statistics
|
|
334
|
-
* @throws {OPFSError} If the file or directory does not exist or cannot be accessed
|
|
336
|
+
* @returns Promise that resolves to FileStat object
|
|
337
|
+
* @throws {OPFSError} If the path does not exist or cannot be accessed
|
|
335
338
|
*
|
|
336
339
|
* @example
|
|
337
340
|
* ```typescript
|
|
338
|
-
*
|
|
339
|
-
* const stats = await fs.stat('/config/settings.json');
|
|
341
|
+
* const stats = await fs.stat('/data/config.json');
|
|
340
342
|
* console.log(`File size: ${stats.size} bytes`);
|
|
341
|
-
* console.log(`
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
* hashAlgorithm: 'SHA-1'
|
|
348
|
-
* });
|
|
349
|
-
* console.log(`Hash: ${statsWithHash.hash}`);
|
|
343
|
+
* console.log(`Last modified: ${stats.mtime}`);
|
|
344
|
+
*
|
|
345
|
+
* // If hashing is enabled, hash will be included
|
|
346
|
+
* if (stats.hash) {
|
|
347
|
+
* console.log(`Hash: ${stats.hash}`);
|
|
348
|
+
* }
|
|
350
349
|
* ```
|
|
351
350
|
*/
|
|
352
|
-
async stat(t
|
|
351
|
+
async stat(t) {
|
|
353
352
|
if (await this.ensureMounted(), t === "/")
|
|
354
353
|
return {
|
|
355
354
|
kind: "directory",
|
|
@@ -359,30 +358,30 @@ class N {
|
|
|
359
358
|
isFile: !1,
|
|
360
359
|
isDirectory: !0
|
|
361
360
|
};
|
|
362
|
-
const
|
|
361
|
+
const e = y(t), i = await this.getDirectoryHandle(u(t), !1), r = this.hashAlgorithm !== null;
|
|
363
362
|
try {
|
|
364
|
-
const
|
|
363
|
+
const s = await (await i.getFileHandle(e, { create: !1 })).getFile(), o = {
|
|
365
364
|
kind: "file",
|
|
366
|
-
size:
|
|
367
|
-
mtime: new Date(
|
|
368
|
-
ctime: new Date(
|
|
365
|
+
size: s.size,
|
|
366
|
+
mtime: new Date(s.lastModified).toISOString(),
|
|
367
|
+
ctime: new Date(s.lastModified).toISOString(),
|
|
369
368
|
isFile: !0,
|
|
370
369
|
isDirectory: !1
|
|
371
370
|
};
|
|
372
|
-
if (
|
|
371
|
+
if (r && this.hashAlgorithm)
|
|
373
372
|
try {
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
} catch (
|
|
377
|
-
console.warn(`Failed to calculate hash for ${t}:`,
|
|
373
|
+
const c = await M(s, this.hashAlgorithm);
|
|
374
|
+
o.hash = c;
|
|
375
|
+
} catch (c) {
|
|
376
|
+
console.warn(`Failed to calculate hash for ${t}:`, c);
|
|
378
377
|
}
|
|
379
|
-
return
|
|
380
|
-
} catch (
|
|
381
|
-
if (
|
|
382
|
-
throw new
|
|
378
|
+
return o;
|
|
379
|
+
} catch (a) {
|
|
380
|
+
if (a.name !== "TypeMismatchError" && a.name !== "NotFoundError")
|
|
381
|
+
throw new n("Failed to stat (file)", "STAT_FAILED");
|
|
383
382
|
}
|
|
384
383
|
try {
|
|
385
|
-
return await
|
|
384
|
+
return await i.getDirectoryHandle(e, { create: !1 }), {
|
|
386
385
|
kind: "directory",
|
|
387
386
|
size: 0,
|
|
388
387
|
mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
@@ -390,8 +389,8 @@ class N {
|
|
|
390
389
|
isFile: !1,
|
|
391
390
|
isDirectory: !0
|
|
392
391
|
};
|
|
393
|
-
} catch (
|
|
394
|
-
throw
|
|
392
|
+
} catch (a) {
|
|
393
|
+
throw a.name === "NotFoundError" ? new n(`No such file or directory: ${t}`, "ENOENT") : new n("Failed to stat (directory)", "STAT_FAILED");
|
|
395
394
|
}
|
|
396
395
|
}
|
|
397
396
|
async readdir(t, e) {
|
|
@@ -399,11 +398,11 @@ class N {
|
|
|
399
398
|
const i = e?.withFileTypes ?? !1, r = await this.getDirectoryHandle(t, !1);
|
|
400
399
|
if (i) {
|
|
401
400
|
const a = [];
|
|
402
|
-
for await (const [
|
|
403
|
-
const c =
|
|
401
|
+
for await (const [s, o] of r.entries()) {
|
|
402
|
+
const c = o.kind === "file";
|
|
404
403
|
a.push({
|
|
405
|
-
name:
|
|
406
|
-
kind:
|
|
404
|
+
name: s,
|
|
405
|
+
kind: o.kind,
|
|
407
406
|
isFile: c,
|
|
408
407
|
isDirectory: !c
|
|
409
408
|
});
|
|
@@ -411,8 +410,8 @@ class N {
|
|
|
411
410
|
return a;
|
|
412
411
|
} else {
|
|
413
412
|
const a = [];
|
|
414
|
-
for await (const [
|
|
415
|
-
a.push(
|
|
413
|
+
for await (const [s] of r.entries())
|
|
414
|
+
a.push(s);
|
|
416
415
|
return a;
|
|
417
416
|
}
|
|
418
417
|
}
|
|
@@ -433,10 +432,10 @@ class N {
|
|
|
433
432
|
async exists(t) {
|
|
434
433
|
if (await this.ensureMounted(), t === "/")
|
|
435
434
|
return !0;
|
|
436
|
-
const e =
|
|
435
|
+
const e = y(t);
|
|
437
436
|
let i = null;
|
|
438
437
|
try {
|
|
439
|
-
i = await this.getDirectoryHandle(
|
|
438
|
+
i = await this.getDirectoryHandle(u(t), !1);
|
|
440
439
|
} catch (r) {
|
|
441
440
|
throw (r.name === "NotFoundError" || r.name === "TypeMismatchError") && (i = null), r;
|
|
442
441
|
}
|
|
@@ -483,9 +482,9 @@ class N {
|
|
|
483
482
|
const r = `${t === "/" ? "" : t}/${i.name}`;
|
|
484
483
|
await this.remove(r, { recursive: !0 });
|
|
485
484
|
}
|
|
486
|
-
this.
|
|
485
|
+
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
487
486
|
} catch (e) {
|
|
488
|
-
throw e instanceof
|
|
487
|
+
throw e instanceof n ? e : new n(`Failed to clear directory: ${t}`, "CLEAR_FAILED");
|
|
489
488
|
}
|
|
490
489
|
}
|
|
491
490
|
/**
|
|
@@ -516,20 +515,20 @@ class N {
|
|
|
516
515
|
await this.ensureMounted();
|
|
517
516
|
const i = e?.recursive ?? !1, r = e?.force ?? !1;
|
|
518
517
|
if (t === "/")
|
|
519
|
-
throw new
|
|
520
|
-
const a =
|
|
518
|
+
throw new n("Cannot remove root directory", "EROOT");
|
|
519
|
+
const a = y(t);
|
|
521
520
|
if (!a)
|
|
522
|
-
throw new
|
|
523
|
-
const
|
|
521
|
+
throw new g("Invalid path", t);
|
|
522
|
+
const s = await this.getDirectoryHandle(u(t), !1);
|
|
524
523
|
try {
|
|
525
|
-
await
|
|
526
|
-
} catch (
|
|
527
|
-
if (
|
|
524
|
+
await s.removeEntry(a, { recursive: i });
|
|
525
|
+
} catch (o) {
|
|
526
|
+
if (o.name === "NotFoundError") {
|
|
528
527
|
if (!r)
|
|
529
|
-
throw new
|
|
530
|
-
} else throw
|
|
528
|
+
throw new n(`No such file or directory: ${t}`, "ENOENT");
|
|
529
|
+
} else throw o.name === "InvalidModificationError" ? new n(`Directory not empty: ${t}. Use recursive option to force removal.`, "ENOTEMPTY") : o.name === "TypeMismatchError" && !i ? new n(`Cannot remove directory without recursive option: ${t}`, "EISDIR") : new n(`Failed to remove path: ${t}`, "RM_FAILED");
|
|
531
530
|
}
|
|
532
|
-
this.
|
|
531
|
+
await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
533
532
|
}
|
|
534
533
|
/**
|
|
535
534
|
* Resolve a path to an absolute path
|
|
@@ -552,12 +551,12 @@ class N {
|
|
|
552
551
|
async realpath(t) {
|
|
553
552
|
await this.ensureMounted();
|
|
554
553
|
try {
|
|
555
|
-
const e =
|
|
554
|
+
const e = A(t);
|
|
556
555
|
if (!await this.exists(e))
|
|
557
|
-
throw new
|
|
556
|
+
throw new f(e);
|
|
558
557
|
return e;
|
|
559
558
|
} catch (e) {
|
|
560
|
-
throw e instanceof
|
|
559
|
+
throw e instanceof n ? e : new n(`Failed to resolve path: ${t}`, "REALPATH_FAILED");
|
|
561
560
|
}
|
|
562
561
|
}
|
|
563
562
|
/**
|
|
@@ -580,10 +579,10 @@ class N {
|
|
|
580
579
|
await this.ensureMounted();
|
|
581
580
|
try {
|
|
582
581
|
if (!await this.exists(t))
|
|
583
|
-
throw new
|
|
584
|
-
await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), this.
|
|
582
|
+
throw new f(t);
|
|
583
|
+
await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
585
584
|
} catch (i) {
|
|
586
|
-
throw i instanceof
|
|
585
|
+
throw i instanceof n ? i : new n(`Failed to rename from ${t} to ${e}`, "RENAME_FAILED");
|
|
587
586
|
}
|
|
588
587
|
}
|
|
589
588
|
/**
|
|
@@ -616,25 +615,25 @@ class N {
|
|
|
616
615
|
try {
|
|
617
616
|
const r = i?.recursive ?? !1, a = i?.force ?? !0;
|
|
618
617
|
if (!await this.exists(t))
|
|
619
|
-
throw new
|
|
618
|
+
throw new n(`Source does not exist: ${t}`, "ENOENT");
|
|
620
619
|
if (await this.exists(e) && !a)
|
|
621
|
-
throw new
|
|
620
|
+
throw new n(`Destination already exists: ${e}`, "EEXIST");
|
|
622
621
|
if ((await this.stat(t)).isFile) {
|
|
623
|
-
const
|
|
624
|
-
await this.writeFile(e,
|
|
622
|
+
const h = await this.readFile(t, "binary");
|
|
623
|
+
await this.writeFile(e, h);
|
|
625
624
|
} else {
|
|
626
625
|
if (!r)
|
|
627
|
-
throw new
|
|
626
|
+
throw new n(`Cannot copy directory without recursive option: ${t}`, "EISDIR");
|
|
628
627
|
await this.mkdir(e, { recursive: !0 });
|
|
629
|
-
const
|
|
630
|
-
for (const
|
|
631
|
-
const
|
|
632
|
-
await this.copy(
|
|
628
|
+
const h = await this.readdir(t, { withFileTypes: !0 });
|
|
629
|
+
for (const m of h) {
|
|
630
|
+
const D = `${t}/${m.name}`, E = `${e}/${m.name}`;
|
|
631
|
+
await this.copy(D, E, { recursive: !0, force: a });
|
|
633
632
|
}
|
|
634
633
|
}
|
|
635
|
-
this.
|
|
634
|
+
await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
636
635
|
} catch (r) {
|
|
637
|
-
throw r instanceof
|
|
636
|
+
throw r instanceof n ? r : new n(`Failed to copy from ${t} to ${e}`, "CP_FAILED");
|
|
638
637
|
}
|
|
639
638
|
}
|
|
640
639
|
/**
|
|
@@ -642,7 +641,7 @@ class N {
|
|
|
642
641
|
*/
|
|
643
642
|
async watch(t) {
|
|
644
643
|
await this.ensureMounted();
|
|
645
|
-
const e =
|
|
644
|
+
const e = d(t), i = await this.buildSnapshot(e);
|
|
646
645
|
this.watchers.set(e, i), this.watchTimer || (this.watchTimer = setInterval(() => {
|
|
647
646
|
this.scanWatches();
|
|
648
647
|
}, this.watchInterval));
|
|
@@ -651,16 +650,16 @@ class N {
|
|
|
651
650
|
* Stop watching a previously watched path
|
|
652
651
|
*/
|
|
653
652
|
unwatch(t) {
|
|
654
|
-
const e =
|
|
653
|
+
const e = d(t);
|
|
655
654
|
this.watchers.delete(e), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
656
655
|
}
|
|
657
656
|
async buildSnapshot(t) {
|
|
658
657
|
const e = /* @__PURE__ */ new Map(), i = async (r) => {
|
|
659
658
|
const a = await this.stat(r);
|
|
660
659
|
if (e.set(r, a), a.isDirectory) {
|
|
661
|
-
const
|
|
662
|
-
for (const
|
|
663
|
-
const c = `${r === "/" ? "" : r}/${
|
|
660
|
+
const s = await this.readdir(r, { withFileTypes: !0 });
|
|
661
|
+
for (const o of s) {
|
|
662
|
+
const c = `${r === "/" ? "" : r}/${o.name}`;
|
|
664
663
|
await i(c);
|
|
665
664
|
}
|
|
666
665
|
}
|
|
@@ -679,16 +678,12 @@ class N {
|
|
|
679
678
|
} catch {
|
|
680
679
|
i = /* @__PURE__ */ new Map();
|
|
681
680
|
}
|
|
682
|
-
const r
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
s ? (s.mtime !== n.mtime || s.size !== n.size) && r.push({ path: a, type: "change" }) : r.push({ path: a, type: "create" });
|
|
681
|
+
for (const [r, a] of i) {
|
|
682
|
+
const s = e.get(r);
|
|
683
|
+
s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: r, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: r, type: "added", isDirectory: !1 });
|
|
686
684
|
}
|
|
687
|
-
for (const
|
|
688
|
-
i.has(
|
|
689
|
-
if (r.length && this.watchCallback)
|
|
690
|
-
for (const a of r)
|
|
691
|
-
this.watchCallback(a);
|
|
685
|
+
for (const r of e.keys())
|
|
686
|
+
i.has(r) || await this.notifyChange({ path: r, type: "removed", isDirectory: !1 });
|
|
692
687
|
this.watchers.set(t, i);
|
|
693
688
|
})
|
|
694
689
|
);
|
|
@@ -730,18 +725,18 @@ class N {
|
|
|
730
725
|
try {
|
|
731
726
|
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
732
727
|
for (const [r, a] of t) {
|
|
733
|
-
const
|
|
734
|
-
let
|
|
735
|
-
a instanceof Blob ?
|
|
728
|
+
const s = d(r);
|
|
729
|
+
let o;
|
|
730
|
+
a instanceof Blob ? o = await $(a) : o = a, await this.writeFile(s, o);
|
|
736
731
|
}
|
|
737
|
-
this.
|
|
732
|
+
await this.notifyChange({ path: "/", type: "changed", isDirectory: !0 });
|
|
738
733
|
} catch (i) {
|
|
739
|
-
throw i instanceof
|
|
734
|
+
throw i instanceof n ? i : new n("Failed to sync file system", "SYNC_FAILED");
|
|
740
735
|
}
|
|
741
736
|
}
|
|
742
737
|
}
|
|
743
|
-
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
738
|
+
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && p(new O());
|
|
744
739
|
export {
|
|
745
|
-
|
|
740
|
+
O as OPFSWorker
|
|
746
741
|
};
|
|
747
742
|
//# sourceMappingURL=raw.js.map
|