@wasmedia/wexiftool 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/LICENSE-exiftool +19 -0
- package/README.md +105 -2
- package/dist/cli.cjs +19 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.es.js +81 -0
- package/dist/index-BUUKaFua.js +681 -0
- package/dist/index-Czh_jOH1.cjs +1 -0
- package/dist/node-6KJNNt7l.cjs +1 -0
- package/dist/node-WHSUCdKF.js +102 -0
- package/dist/wexiftool-CUKoJisL.js +761 -0
- package/dist/wexiftool-Dt9AnMsh.cjs +4 -0
- package/dist/wexiftool.cjs +1 -0
- package/dist/wexiftool.d.ts +255 -0
- package/dist/wexiftool.es.js +5 -0
- package/dist/worker.cjs +1 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.es.js +64 -0
- package/package.json +69 -4
- package/wasm/package.json +4 -0
- package/wasm/perl.js +2 -0
- package/wasm/perl.wasm +4 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
var V = Object.defineProperty;
|
|
2
|
+
var Y = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var O = (e, t, n) => Y(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { a as b, b as $, c as z, d as H, e as D, f as I, g as L } from "./wexiftool-CUKoJisL.js";
|
|
5
|
+
function q(e) {
|
|
6
|
+
if (!e.startsWith("/") || e === "/" || e.endsWith("/"))
|
|
7
|
+
throw new b(`mountpoint must be an absolute path other than "/", without a trailing slash: ${e}`);
|
|
8
|
+
}
|
|
9
|
+
function K(e) {
|
|
10
|
+
if (e.split("/").some((n) => n === "" || n === "." || n === ".."))
|
|
11
|
+
throw new b(`input path must be relative and normalized: ${JSON.stringify(e)}`);
|
|
12
|
+
}
|
|
13
|
+
function T(e, t) {
|
|
14
|
+
const n = e.analyzePath(t);
|
|
15
|
+
if (n.exists) {
|
|
16
|
+
if (!n.object || !e.isDir(n.object.mode))
|
|
17
|
+
throw new b(`${t} exists and is not a directory`);
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const s = t.split("/").slice(1), a = s.map((l, f) => "/" + s.slice(0, f + 1).join("/")).filter((l) => !e.analyzePath(l).exists);
|
|
21
|
+
return e.mkdirTree(t), a;
|
|
22
|
+
}
|
|
23
|
+
function M(e, t) {
|
|
24
|
+
for (const n of [...t].reverse())
|
|
25
|
+
e.rmdir(n);
|
|
26
|
+
}
|
|
27
|
+
function A(e, t) {
|
|
28
|
+
for (const n of e.streams)
|
|
29
|
+
if (n && n.node.mount === t)
|
|
30
|
+
try {
|
|
31
|
+
e.close(n);
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function U(e, t) {
|
|
36
|
+
return (t == null ? void 0 : t.name) === "ErrnoError" ? new b(`cannot mount at ${e} (errno ${t.errno}); is it already a mount point?`, { cause: t }) : t;
|
|
37
|
+
}
|
|
38
|
+
function _(e, t, n, s) {
|
|
39
|
+
A(e, n);
|
|
40
|
+
const a = s[0] ?? t, l = e.cwd();
|
|
41
|
+
(l === a || l.startsWith(`${a}/`)) && e.chdir(a.slice(0, a.lastIndexOf("/")) || "/");
|
|
42
|
+
try {
|
|
43
|
+
e.unmount(t);
|
|
44
|
+
} catch (f) {
|
|
45
|
+
const h = f == null ? void 0 : f.errno;
|
|
46
|
+
throw new $(`cannot unmount ${t} (errno ${h}); release() can be retried`, { cause: f });
|
|
47
|
+
}
|
|
48
|
+
M(e, s);
|
|
49
|
+
}
|
|
50
|
+
function x() {
|
|
51
|
+
var s, a;
|
|
52
|
+
const e = globalThis;
|
|
53
|
+
if ((a = (s = e.process) == null ? void 0 : s.versions) != null && a.node && typeof e.window > "u")
|
|
54
|
+
return "node";
|
|
55
|
+
const t = e.DedicatedWorkerGlobalScope, n = e.FileSystemFileHandle;
|
|
56
|
+
return typeof t == "function" && globalThis instanceof t && n && "createSyncAccessHandle" in n.prototype ? "opfs" : "memfs";
|
|
57
|
+
}
|
|
58
|
+
const Q = [
|
|
59
|
+
"ErrnoError",
|
|
60
|
+
"createNode",
|
|
61
|
+
"hashRemoveNode",
|
|
62
|
+
"isDir",
|
|
63
|
+
"isFile",
|
|
64
|
+
"mount",
|
|
65
|
+
"unmount",
|
|
66
|
+
"lookupPath",
|
|
67
|
+
"analyzePath",
|
|
68
|
+
"mkdirTree",
|
|
69
|
+
"rmdir",
|
|
70
|
+
"readdir",
|
|
71
|
+
"writeFile",
|
|
72
|
+
"readFile",
|
|
73
|
+
"chmod",
|
|
74
|
+
"close",
|
|
75
|
+
"cwd",
|
|
76
|
+
"chdir"
|
|
77
|
+
];
|
|
78
|
+
function G(e) {
|
|
79
|
+
var s;
|
|
80
|
+
const t = e == null ? void 0 : e.FS;
|
|
81
|
+
if (!t)
|
|
82
|
+
throw new z("module has no FS export; build it with -sEXPORTED_RUNTIME_METHODS=FS");
|
|
83
|
+
const n = Q.filter((a) => typeof t[a] != "function");
|
|
84
|
+
if (Array.isArray(t.streams) || n.push("streams"), (s = t.filesystems) != null && s.MEMFS || n.push("filesystems.MEMFS"), n.length)
|
|
85
|
+
throw new z(`module.FS is missing ${n.join(", ")}: this Emscripten's FS internals differ from the ones wopfs supports (emsdk 5.0.5, 5.0.6)`);
|
|
86
|
+
}
|
|
87
|
+
const E = {
|
|
88
|
+
EACCES: 2,
|
|
89
|
+
EINVAL: 28,
|
|
90
|
+
EIO: 29,
|
|
91
|
+
ENODEV: 43,
|
|
92
|
+
ENOENT: 44,
|
|
93
|
+
ENOSPC: 51,
|
|
94
|
+
ENOTEMPTY: 55,
|
|
95
|
+
EPERM: 63,
|
|
96
|
+
EROFS: 69
|
|
97
|
+
}, X = 0, Z = 1, tt = 2, et = 61440, R = 16384, nt = 32768, C = R | 511, st = nt | 292, g = (e) => (e.mode & et) === R;
|
|
98
|
+
function rt(e) {
|
|
99
|
+
const t = e._malloc;
|
|
100
|
+
return typeof t != "function" || !e.HEAPU8 ? () => null : (n) => {
|
|
101
|
+
const s = t(n);
|
|
102
|
+
return s ? { ptr: s, heap: e.HEAPU8, free: () => {
|
|
103
|
+
var a;
|
|
104
|
+
return (a = e._free) == null ? void 0 : a.call(e, s);
|
|
105
|
+
} } : null;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function ot(e, t) {
|
|
109
|
+
const n = (r) => new e.ErrnoError(r);
|
|
110
|
+
function s(r) {
|
|
111
|
+
try {
|
|
112
|
+
return r();
|
|
113
|
+
} catch (o) {
|
|
114
|
+
const { name: i, code: c } = o ?? {};
|
|
115
|
+
throw i === "ErrnoError" ? o : n(i === "QuotaExceededError" || c === "ENOSPC" || c === "EDQUOT" ? E.ENOSPC : E.EIO);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const a = (r) => r.wopfs;
|
|
119
|
+
function l(r, o, i, c) {
|
|
120
|
+
const u = e.createNode(r, o, i, 0);
|
|
121
|
+
return u.node_ops = y, u.stream_ops = d, u.atime = u.mtime = u.ctime = Date.now(), g(u) ? u.contents = /* @__PURE__ */ Object.create(null) : u.wopfs = c, r && (r.contents[o] = u, r.mtime = r.ctime = u.mtime), u;
|
|
122
|
+
}
|
|
123
|
+
function f(r) {
|
|
124
|
+
const o = r.wopfs;
|
|
125
|
+
!o || o.input || (o.unlinked = !0, o.openCount === 0 && t.discardFile(o.file));
|
|
126
|
+
}
|
|
127
|
+
function h(r) {
|
|
128
|
+
const o = a(r);
|
|
129
|
+
if (o.input)
|
|
130
|
+
throw n(E.EACCES);
|
|
131
|
+
return o;
|
|
132
|
+
}
|
|
133
|
+
const w = (r) => {
|
|
134
|
+
r.mtime = r.ctime = Date.now();
|
|
135
|
+
}, y = {
|
|
136
|
+
getattr(r) {
|
|
137
|
+
const o = g(r) ? 4096 : a(r).size;
|
|
138
|
+
return {
|
|
139
|
+
dev: 1,
|
|
140
|
+
ino: r.id,
|
|
141
|
+
mode: r.mode,
|
|
142
|
+
nlink: 1,
|
|
143
|
+
uid: 0,
|
|
144
|
+
gid: 0,
|
|
145
|
+
rdev: 0,
|
|
146
|
+
size: o,
|
|
147
|
+
atime: new Date(r.atime),
|
|
148
|
+
mtime: new Date(r.mtime),
|
|
149
|
+
ctime: new Date(r.ctime),
|
|
150
|
+
blksize: 4096,
|
|
151
|
+
blocks: Math.ceil(o / 4096)
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
setattr(r, o) {
|
|
155
|
+
for (const i of ["mode", "atime", "mtime", "ctime"])
|
|
156
|
+
o[i] != null && (r[i] = o[i]);
|
|
157
|
+
if (o.size !== void 0) {
|
|
158
|
+
const i = h(r), c = o.size;
|
|
159
|
+
s(() => i.file.truncate(c)), i.size = c, w(r);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
lookup(r, o) {
|
|
163
|
+
const i = r.contents[o];
|
|
164
|
+
if (i)
|
|
165
|
+
return i;
|
|
166
|
+
throw n(E.ENOENT);
|
|
167
|
+
},
|
|
168
|
+
mknod(r, o, i) {
|
|
169
|
+
if (t.readOnly)
|
|
170
|
+
throw n(E.EROFS);
|
|
171
|
+
if (e.isDir(i))
|
|
172
|
+
return l(r, o, i);
|
|
173
|
+
if (!e.isFile(i))
|
|
174
|
+
throw n(E.EPERM);
|
|
175
|
+
const c = s(() => t.createFile());
|
|
176
|
+
if (!c)
|
|
177
|
+
throw n(E.ENOSPC);
|
|
178
|
+
return l(r, o, i, { file: c, size: 0, input: !1, openCount: 0, unlinked: !1 });
|
|
179
|
+
},
|
|
180
|
+
rename(r, o, i) {
|
|
181
|
+
const c = o.contents[i];
|
|
182
|
+
if (c) {
|
|
183
|
+
if (g(c) && Object.keys(c.contents).length)
|
|
184
|
+
throw n(E.ENOTEMPTY);
|
|
185
|
+
e.hashRemoveNode(c), f(c);
|
|
186
|
+
}
|
|
187
|
+
delete r.parent.contents[r.name], o.contents[i] = r, r.name = i, w(o), w(r.parent);
|
|
188
|
+
},
|
|
189
|
+
unlink(r, o) {
|
|
190
|
+
const i = r.contents[o];
|
|
191
|
+
delete r.contents[o], w(r), f(i);
|
|
192
|
+
},
|
|
193
|
+
rmdir(r, o) {
|
|
194
|
+
const i = r.contents[o];
|
|
195
|
+
if (Object.keys(i.contents).length)
|
|
196
|
+
throw n(E.ENOTEMPTY);
|
|
197
|
+
delete r.contents[o], w(r);
|
|
198
|
+
},
|
|
199
|
+
readdir(r) {
|
|
200
|
+
return [".", "..", ...Object.keys(r.contents)];
|
|
201
|
+
},
|
|
202
|
+
symlink() {
|
|
203
|
+
throw n(E.EPERM);
|
|
204
|
+
}
|
|
205
|
+
}, d = {
|
|
206
|
+
open(r) {
|
|
207
|
+
if (g(r.node))
|
|
208
|
+
return;
|
|
209
|
+
const o = (r.flags & 3) === X ? a(r.node) : h(r.node);
|
|
210
|
+
o.openCount++;
|
|
211
|
+
},
|
|
212
|
+
dup(r) {
|
|
213
|
+
g(r.node) || a(r.node).openCount++;
|
|
214
|
+
},
|
|
215
|
+
close(r) {
|
|
216
|
+
if (g(r.node))
|
|
217
|
+
return;
|
|
218
|
+
const o = a(r.node);
|
|
219
|
+
o.openCount--, o.unlinked ? o.openCount === 0 && t.discardFile(o.file) : o.input || s(() => o.file.flush());
|
|
220
|
+
},
|
|
221
|
+
read(r, o, i, c, u) {
|
|
222
|
+
const p = a(r.node);
|
|
223
|
+
if (u >= p.size)
|
|
224
|
+
return 0;
|
|
225
|
+
const m = Math.min(c, p.size - u);
|
|
226
|
+
return s(() => p.file.read(new Uint8Array(o.buffer, o.byteOffset + i, m), u));
|
|
227
|
+
},
|
|
228
|
+
write(r, o, i, c, u) {
|
|
229
|
+
if (!c)
|
|
230
|
+
return 0;
|
|
231
|
+
const p = h(r.node), m = s(() => p.file.write(new Uint8Array(o.buffer, o.byteOffset + i, c), u));
|
|
232
|
+
return p.size = Math.max(p.size, u + m), w(r.node), m;
|
|
233
|
+
},
|
|
234
|
+
llseek(r, o, i) {
|
|
235
|
+
let c = o;
|
|
236
|
+
if (i === Z ? c += r.position : i === tt && !g(r.node) && (c += a(r.node).size), c < 0)
|
|
237
|
+
throw n(E.EINVAL);
|
|
238
|
+
return c;
|
|
239
|
+
},
|
|
240
|
+
/** Served by copying into the heap: a memory cost, documented in the README. */
|
|
241
|
+
mmap(r, o, i) {
|
|
242
|
+
if (g(r.node))
|
|
243
|
+
throw n(E.ENODEV);
|
|
244
|
+
const c = t.mmapAlloc(o);
|
|
245
|
+
if (!c)
|
|
246
|
+
throw n(E.ENODEV);
|
|
247
|
+
const u = c.heap.subarray(c.ptr, c.ptr + o), p = a(r.node), m = i < p.size ? Math.min(o, p.size - i) : 0;
|
|
248
|
+
if (m)
|
|
249
|
+
try {
|
|
250
|
+
s(() => p.file.read(u.subarray(0, m), i));
|
|
251
|
+
} catch (k) {
|
|
252
|
+
throw c.free(), k;
|
|
253
|
+
}
|
|
254
|
+
return u.fill(0, m), { ptr: c.ptr, allocated: !0 };
|
|
255
|
+
},
|
|
256
|
+
msync(r, o, i, c) {
|
|
257
|
+
return d.write(r, o, 0, c, i), 0;
|
|
258
|
+
},
|
|
259
|
+
fsync(r) {
|
|
260
|
+
return g(r.node) || s(() => a(r.node).file.flush()), 0;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
return {
|
|
264
|
+
mount(r) {
|
|
265
|
+
const o = l(null, "/", C);
|
|
266
|
+
o.mount = r;
|
|
267
|
+
for (const { path: i, file: c } of r.opts.inputs ?? []) {
|
|
268
|
+
const u = i.split("/");
|
|
269
|
+
let p = o;
|
|
270
|
+
for (const m of u.slice(0, -1))
|
|
271
|
+
p = p.contents[m] ?? l(p, m, C);
|
|
272
|
+
l(p, u[u.length - 1], st, {
|
|
273
|
+
file: c,
|
|
274
|
+
size: c.getSize(),
|
|
275
|
+
input: !0,
|
|
276
|
+
openCount: 0,
|
|
277
|
+
unlinked: !1
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return o;
|
|
281
|
+
},
|
|
282
|
+
node_ops: y,
|
|
283
|
+
stream_ops: d
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function it(e) {
|
|
287
|
+
const t = [], n = (s, a) => {
|
|
288
|
+
for (const [l, f] of Object.entries(s.contents)) {
|
|
289
|
+
const h = a ? `${a}/${l}` : l;
|
|
290
|
+
g(f) ? n(f, h) : f.wopfs && !f.wopfs.input && t.push({ path: h, backing: f.wopfs });
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
return n(e, ""), t.sort((s, a) => s.path < a.path ? -1 : s.path > a.path ? 1 : 0);
|
|
294
|
+
}
|
|
295
|
+
class j {
|
|
296
|
+
constructor(t) {
|
|
297
|
+
O(this, "data");
|
|
298
|
+
O(this, "size");
|
|
299
|
+
this.data = t ?? new Uint8Array(0), this.size = this.data.length;
|
|
300
|
+
}
|
|
301
|
+
read(t, n) {
|
|
302
|
+
const s = Math.max(0, Math.min(t.length, this.size - n));
|
|
303
|
+
return t.set(this.data.subarray(n, n + s)), s;
|
|
304
|
+
}
|
|
305
|
+
write(t, n) {
|
|
306
|
+
const s = n + t.length;
|
|
307
|
+
return this.reserve(s), n > this.size && this.data.fill(0, this.size, n), this.data.set(t, n), this.size = Math.max(this.size, s), t.length;
|
|
308
|
+
}
|
|
309
|
+
truncate(t) {
|
|
310
|
+
t > this.size && (this.reserve(t), this.data.fill(0, this.size, t)), this.size = t;
|
|
311
|
+
}
|
|
312
|
+
getSize() {
|
|
313
|
+
return this.size;
|
|
314
|
+
}
|
|
315
|
+
flush() {
|
|
316
|
+
}
|
|
317
|
+
close() {
|
|
318
|
+
}
|
|
319
|
+
bytes() {
|
|
320
|
+
return this.data.subarray(0, this.size);
|
|
321
|
+
}
|
|
322
|
+
reserve(t) {
|
|
323
|
+
if (t <= this.data.length)
|
|
324
|
+
return;
|
|
325
|
+
const n = new Uint8Array(Math.max(t, this.data.length * 2, 4096));
|
|
326
|
+
n.set(this.data.subarray(0, this.size)), this.data = n;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function at(e) {
|
|
330
|
+
let t = !1;
|
|
331
|
+
return {
|
|
332
|
+
read: (n, s) => e.read(n, { at: s }),
|
|
333
|
+
write: (n, s) => e.write(n, { at: s }),
|
|
334
|
+
truncate: (n) => e.truncate(n),
|
|
335
|
+
getSize: () => e.getSize(),
|
|
336
|
+
flush: () => e.flush(),
|
|
337
|
+
close: () => {
|
|
338
|
+
t || (t = !0, e.close());
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
const ct = 1 << 20;
|
|
343
|
+
function lt(e, t, n) {
|
|
344
|
+
const s = new Uint8Array(Math.min(ct, Math.max(n, 1)));
|
|
345
|
+
t.truncate(0);
|
|
346
|
+
for (let a = 0; a < n; ) {
|
|
347
|
+
const l = e.read(s.subarray(0, Math.min(s.length, n - a)), a);
|
|
348
|
+
if (l <= 0)
|
|
349
|
+
break;
|
|
350
|
+
t.write(s.subarray(0, l), a), a += l;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
class W {
|
|
354
|
+
constructor(t) {
|
|
355
|
+
O(this, "options");
|
|
356
|
+
O(this, "slots");
|
|
357
|
+
O(this, "free");
|
|
358
|
+
O(this, "byFile", /* @__PURE__ */ new Map());
|
|
359
|
+
O(this, "warned", !1);
|
|
360
|
+
this.options = t, this.slots = [...t.preopened ?? []], this.free = [...this.slots].reverse();
|
|
361
|
+
for (const n of this.slots)
|
|
362
|
+
this.byFile.set(n.file, n);
|
|
363
|
+
}
|
|
364
|
+
acquire() {
|
|
365
|
+
let t = this.free.pop();
|
|
366
|
+
return !t && this.options.open && this.slots.length < this.options.capacity && (t = this.options.open(this.slots.length), this.slots.push(t), this.byFile.set(t.file, t)), t ? t.file : this.options.onExhausted === "strict" ? null : (this.warned || (this.warned = !0, this.options.warn(`wopfs: scratch pool of ${this.options.capacity} exhausted; holding further new files in memory until commit()`)), new j());
|
|
367
|
+
}
|
|
368
|
+
/** The file is unreachable and closed. A spilled file is simply dropped. */
|
|
369
|
+
discard(t) {
|
|
370
|
+
const n = this.byFile.get(t);
|
|
371
|
+
if (n) {
|
|
372
|
+
try {
|
|
373
|
+
t.truncate(0);
|
|
374
|
+
} catch {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
this.free.push(n);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
slotOf(t) {
|
|
381
|
+
return this.byFile.get(t);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
function ft(e, t, n) {
|
|
385
|
+
const s = e.FS, a = T(s, t), l = ot(s, {
|
|
386
|
+
createFile: () => n.pool.acquire(),
|
|
387
|
+
discardFile: (w) => n.pool.discard(w),
|
|
388
|
+
mmapAlloc: rt(e),
|
|
389
|
+
readOnly: n.readOnly
|
|
390
|
+
});
|
|
391
|
+
let f;
|
|
392
|
+
try {
|
|
393
|
+
f = s.mount(l, { inputs: n.inputs }, t);
|
|
394
|
+
} catch (w) {
|
|
395
|
+
throw M(s, a), U(t, w);
|
|
396
|
+
}
|
|
397
|
+
let h = "mounted";
|
|
398
|
+
return {
|
|
399
|
+
backend: n.kind,
|
|
400
|
+
mountpoint: t,
|
|
401
|
+
async commit() {
|
|
402
|
+
if (h !== "mounted")
|
|
403
|
+
throw new $(`commit() on a mount that is ${h}`);
|
|
404
|
+
h = "committing", A(s, f.mount);
|
|
405
|
+
for (const { file: y } of n.inputs)
|
|
406
|
+
y.close();
|
|
407
|
+
const w = [];
|
|
408
|
+
try {
|
|
409
|
+
for (const { path: y, backing: d } of it(f))
|
|
410
|
+
w.push(await n.commitFile(y, d.file, d.size));
|
|
411
|
+
} catch (y) {
|
|
412
|
+
throw new H(w, y);
|
|
413
|
+
}
|
|
414
|
+
return h = "committed", w;
|
|
415
|
+
},
|
|
416
|
+
async release() {
|
|
417
|
+
if (h !== "released") {
|
|
418
|
+
h = "releasing";
|
|
419
|
+
try {
|
|
420
|
+
_(s, t, f.mount, a);
|
|
421
|
+
} finally {
|
|
422
|
+
await n.release();
|
|
423
|
+
}
|
|
424
|
+
h = "released";
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function ut(e, t, n) {
|
|
430
|
+
return {
|
|
431
|
+
kind: e,
|
|
432
|
+
inputs: t,
|
|
433
|
+
readOnly: !0,
|
|
434
|
+
pool: new W({ capacity: 0, onExhausted: "strict", warn: () => {
|
|
435
|
+
} }),
|
|
436
|
+
async commitFile(s) {
|
|
437
|
+
throw new $(`an input-only mount (no outputDir) cannot commit ${s}`);
|
|
438
|
+
},
|
|
439
|
+
release: n
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function B(e) {
|
|
443
|
+
return typeof e == "object" && e !== null && e.kind === "file" && typeof e.getFile == "function";
|
|
444
|
+
}
|
|
445
|
+
function ht(e) {
|
|
446
|
+
return typeof e == "object" && e !== null && e.kind === "directory" && typeof e.getFileHandle == "function";
|
|
447
|
+
}
|
|
448
|
+
const dt = {
|
|
449
|
+
opfs: "a FileSystemFileHandle, Uint8Array or Blob",
|
|
450
|
+
node: "a host path string, Uint8Array or Blob",
|
|
451
|
+
memfs: "a Uint8Array, Blob or FileSystemFileHandle"
|
|
452
|
+
};
|
|
453
|
+
async function J(e, t, n) {
|
|
454
|
+
if (e instanceof Uint8Array)
|
|
455
|
+
return e;
|
|
456
|
+
if (typeof Blob < "u" && e instanceof Blob)
|
|
457
|
+
return new Uint8Array(await e.arrayBuffer());
|
|
458
|
+
if (n === "memfs" && B(e))
|
|
459
|
+
return new Uint8Array(await (await e.getFile()).arrayBuffer());
|
|
460
|
+
throw new b(`input ${t}: the ${n} backend takes ${dt[n]}`);
|
|
461
|
+
}
|
|
462
|
+
function pt() {
|
|
463
|
+
return globalThis.crypto.randomUUID().slice(0, 8);
|
|
464
|
+
}
|
|
465
|
+
async function N(e, t) {
|
|
466
|
+
let n;
|
|
467
|
+
try {
|
|
468
|
+
n = await e.createSyncAccessHandle();
|
|
469
|
+
} catch (s) {
|
|
470
|
+
const a = s == null ? void 0 : s.name;
|
|
471
|
+
throw a === "NoModificationAllowedError" || a === "InvalidStateError" ? new I(t, s) : s;
|
|
472
|
+
}
|
|
473
|
+
if (typeof n.getSize() != "number")
|
|
474
|
+
throw await n.close(), new D("this browser's FileSystemSyncAccessHandle methods are asynchronous; wopfs needs the synchronous ones");
|
|
475
|
+
return at(n);
|
|
476
|
+
}
|
|
477
|
+
async function wt(e, t, n) {
|
|
478
|
+
try {
|
|
479
|
+
await e.move(t, n);
|
|
480
|
+
} catch (s) {
|
|
481
|
+
if ((s == null ? void 0 : s.name) !== "InvalidModificationError")
|
|
482
|
+
throw s;
|
|
483
|
+
await t.removeEntry(n), await e.move(t, n);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
async function mt(e, t, n, s, a) {
|
|
487
|
+
const l = await N(t, n);
|
|
488
|
+
try {
|
|
489
|
+
lt(e, l, s), l.flush();
|
|
490
|
+
} catch (f) {
|
|
491
|
+
throw l.close(), await a().catch(() => {
|
|
492
|
+
}), f;
|
|
493
|
+
}
|
|
494
|
+
l.close();
|
|
495
|
+
}
|
|
496
|
+
async function yt(e) {
|
|
497
|
+
const t = e.outputDir;
|
|
498
|
+
if (t !== void 0 && !ht(t))
|
|
499
|
+
throw new b("the opfs backend needs outputDir to be a FileSystemDirectoryHandle");
|
|
500
|
+
if (t === void 0 && e.scratch > 0)
|
|
501
|
+
throw new b(`scratch (${e.scratch}) needs outputDir: without it the mount is input-only`);
|
|
502
|
+
const n = [], s = `.wopfs-scratch-${pt()}`;
|
|
503
|
+
let a, l = 0;
|
|
504
|
+
const f = async () => {
|
|
505
|
+
for (const h of n)
|
|
506
|
+
try {
|
|
507
|
+
h.close();
|
|
508
|
+
} catch {
|
|
509
|
+
}
|
|
510
|
+
a && await t.removeEntry(s, { recursive: !0 }).catch(() => {
|
|
511
|
+
});
|
|
512
|
+
};
|
|
513
|
+
try {
|
|
514
|
+
const h = [], w = [];
|
|
515
|
+
for (const [o, i] of e.inputs)
|
|
516
|
+
if (B(i)) {
|
|
517
|
+
for (const [u, p] of w)
|
|
518
|
+
if (await p.isSameEntry(i))
|
|
519
|
+
throw new b(`inputs ${JSON.stringify(u)} and ${JSON.stringify(o)} are the same file`);
|
|
520
|
+
w.push([o, i]);
|
|
521
|
+
const c = await N(i, o);
|
|
522
|
+
n.push(c), h.push({ path: o, file: c });
|
|
523
|
+
} else
|
|
524
|
+
h.push({ path: o, file: new j(await J(i, o, "opfs")) });
|
|
525
|
+
if (t === void 0)
|
|
526
|
+
return ut("opfs", h, f);
|
|
527
|
+
if (a = await t.getDirectoryHandle(s, { create: !0 }), typeof (await a.getFileHandle("probe", { create: !0 })).move != "function")
|
|
528
|
+
throw new D("this browser's FileSystemFileHandle has no move(); wopfs needs it to commit outputs safely");
|
|
529
|
+
const d = [];
|
|
530
|
+
for (let o = 0; o < e.scratch; o++) {
|
|
531
|
+
const i = `s${o}`, c = await a.getFileHandle(i, { create: !0 }), u = await N(c, `${s}/${i}`);
|
|
532
|
+
n.push(u), d.push({ name: i, file: u, handle: c });
|
|
533
|
+
}
|
|
534
|
+
const r = new W({ capacity: e.scratch, onExhausted: e.onExhausted, preopened: d, warn: e.warn });
|
|
535
|
+
return {
|
|
536
|
+
kind: "opfs",
|
|
537
|
+
inputs: h,
|
|
538
|
+
pool: r,
|
|
539
|
+
async commitFile(o, i, c) {
|
|
540
|
+
const u = o.split("/"), p = u.pop();
|
|
541
|
+
let m = t;
|
|
542
|
+
for (const F of u)
|
|
543
|
+
m = await m.getDirectoryHandle(F, { create: !0 });
|
|
544
|
+
const k = r.slotOf(i);
|
|
545
|
+
let S;
|
|
546
|
+
if (k)
|
|
547
|
+
i.flush(), i.close(), S = k.handle;
|
|
548
|
+
else {
|
|
549
|
+
const F = `spill${l++}`;
|
|
550
|
+
S = await a.getFileHandle(F, { create: !0 }), await mt(i, S, `${s}/${F}`, c, () => a.removeEntry(F)), i.close();
|
|
551
|
+
}
|
|
552
|
+
return await wt(S, m, p), { path: o, size: c, handle: S };
|
|
553
|
+
},
|
|
554
|
+
release: f
|
|
555
|
+
};
|
|
556
|
+
} catch (h) {
|
|
557
|
+
throw await f(), h;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
async function P(e, t, n) {
|
|
561
|
+
const s = e.FS, a = [];
|
|
562
|
+
for (const [d, r] of n.inputs)
|
|
563
|
+
a.push([d, await J(r, d, "memfs")]);
|
|
564
|
+
const l = T(s, t);
|
|
565
|
+
let f;
|
|
566
|
+
try {
|
|
567
|
+
f = s.mount(s.filesystems.MEMFS, {}, t);
|
|
568
|
+
} catch (d) {
|
|
569
|
+
throw M(s, l), U(t, d);
|
|
570
|
+
}
|
|
571
|
+
const h = /* @__PURE__ */ new Set();
|
|
572
|
+
try {
|
|
573
|
+
for (const [d, r] of a) {
|
|
574
|
+
const o = `${t}/${d}`;
|
|
575
|
+
s.mkdirTree(o.slice(0, o.lastIndexOf("/"))), s.writeFile(o, r), s.chmod(o, 292), h.add(s.lookupPath(o).node);
|
|
576
|
+
}
|
|
577
|
+
} catch (d) {
|
|
578
|
+
throw s.unmount(t), M(s, l), d;
|
|
579
|
+
}
|
|
580
|
+
const w = (d, r, o) => {
|
|
581
|
+
for (const i of s.readdir(d)) {
|
|
582
|
+
if (i === "." || i === "..")
|
|
583
|
+
continue;
|
|
584
|
+
const c = `${d}/${i}`, u = r ? `${r}/${i}` : i, p = s.lookupPath(c).node;
|
|
585
|
+
if (s.isDir(p.mode))
|
|
586
|
+
w(c, u, o);
|
|
587
|
+
else if (s.isFile(p.mode) && !h.has(p)) {
|
|
588
|
+
const m = s.readFile(c);
|
|
589
|
+
o.push({ path: u, size: m.length, bytes: m });
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
let y = "mounted";
|
|
594
|
+
return {
|
|
595
|
+
backend: "memfs",
|
|
596
|
+
mountpoint: t,
|
|
597
|
+
async commit() {
|
|
598
|
+
if (y !== "mounted")
|
|
599
|
+
throw new $(`commit() on a mount that is ${y}`);
|
|
600
|
+
A(s, f.mount);
|
|
601
|
+
const d = [];
|
|
602
|
+
return w(t, "", d), y = "committed", d.sort((r, o) => r.path < o.path ? -1 : r.path > o.path ? 1 : 0);
|
|
603
|
+
},
|
|
604
|
+
async release() {
|
|
605
|
+
y !== "released" && (y = "releasing", _(s, t, f.mount, l), y = "released");
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
function Et(e) {
|
|
610
|
+
const t = Object.entries(e.inputs ?? {});
|
|
611
|
+
for (const [l] of t)
|
|
612
|
+
K(l);
|
|
613
|
+
const n = new Set(t.map(([l]) => l));
|
|
614
|
+
for (const [l] of t) {
|
|
615
|
+
const f = l.split("/");
|
|
616
|
+
for (let h = 1; h < f.length; h++) {
|
|
617
|
+
const w = f.slice(0, h).join("/");
|
|
618
|
+
if (n.has(w))
|
|
619
|
+
throw new b(`input ${JSON.stringify(w)} is a file, but ${JSON.stringify(l)} needs it to be a directory`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const s = e.scratch ?? (e.outputDir === void 0 ? 0 : 16);
|
|
623
|
+
if (!Number.isInteger(s) || s < 0)
|
|
624
|
+
throw new b(`scratch must be a non-negative integer: ${s}`);
|
|
625
|
+
const a = e.onExhausted ?? "spill";
|
|
626
|
+
if (a !== "spill" && a !== "strict")
|
|
627
|
+
throw new b(`onExhausted must be "spill" or "strict": ${a}`);
|
|
628
|
+
return {
|
|
629
|
+
inputs: t,
|
|
630
|
+
outputDir: e.outputDir,
|
|
631
|
+
scratch: s,
|
|
632
|
+
onExhausted: a,
|
|
633
|
+
warn: e.onWarning ?? ((l) => console.warn(l))
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
async function v(e, t, n) {
|
|
637
|
+
try {
|
|
638
|
+
return ft(e, t, n);
|
|
639
|
+
} catch (s) {
|
|
640
|
+
throw await n.release(), s;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async function bt(e, t, n = {}) {
|
|
644
|
+
G(e), q(t);
|
|
645
|
+
const s = Et(n), a = n.backend ?? "auto", l = a === "auto" ? x() : a;
|
|
646
|
+
if (l === "memfs")
|
|
647
|
+
return P(e, t, s);
|
|
648
|
+
if (l === "node") {
|
|
649
|
+
const { openNodeBackend: f } = await import("./node-WHSUCdKF.js");
|
|
650
|
+
return v(e, t, await f(s));
|
|
651
|
+
}
|
|
652
|
+
if (l !== "opfs")
|
|
653
|
+
throw new b(`unknown backend: ${String(l)}`);
|
|
654
|
+
try {
|
|
655
|
+
return await v(e, t, await yt(s));
|
|
656
|
+
} catch (f) {
|
|
657
|
+
if (a === "auto" && f instanceof D)
|
|
658
|
+
return s.warn(`wopfs: ${f.message}; falling back to memfs`), P(e, t, s);
|
|
659
|
+
throw f;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const St = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
663
|
+
__proto__: null,
|
|
664
|
+
WopfsCommitError: H,
|
|
665
|
+
WopfsError: L,
|
|
666
|
+
WopfsInputError: b,
|
|
667
|
+
WopfsLockedError: I,
|
|
668
|
+
WopfsRuntimeError: z,
|
|
669
|
+
WopfsStateError: $,
|
|
670
|
+
WopfsUnsupportedError: D,
|
|
671
|
+
detectBackend: x,
|
|
672
|
+
mountFiles: bt
|
|
673
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
674
|
+
export {
|
|
675
|
+
j as M,
|
|
676
|
+
W as S,
|
|
677
|
+
St as a,
|
|
678
|
+
J as b,
|
|
679
|
+
ut as i,
|
|
680
|
+
pt as r
|
|
681
|
+
};
|