@wasmedia/wexiftool 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +4 -6
- package/dist/cli.es.js +144 -58
- package/dist/{index-BUUKaFua.js → index-C7MUqxoE.js} +2 -2
- package/dist/{index-Czh_jOH1.cjs → index-CwcAkqsP.cjs} +1 -1
- package/dist/{node-WHSUCdKF.js → node-Cu1famID.js} +2 -2
- package/dist/{node-6KJNNt7l.cjs → node-RbU1bgHg.cjs} +1 -1
- package/dist/wexiftool-CRI8zlju.js +948 -0
- package/dist/wexiftool-e6N3ift5.cjs +7 -0
- package/dist/wexiftool.cjs +1 -1
- package/dist/wexiftool.d.ts +18 -2
- package/dist/wexiftool.es.js +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.es.js +2 -2
- package/package.json +1 -1
- package/wasm/perl.wasm +1 -1
- package/dist/wexiftool-CUKoJisL.js +0 -761
- package/dist/wexiftool-Dt9AnMsh.cjs +0 -4
package/dist/cli.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
`),l.stderr&&process.stderr.write(l.stderr+`
|
|
6
|
-
`),s.destroy(),process.exit(l.exitCode)}function x(t){const o=[],i=[],c=new Set(["-tagsFromFile","-tagsfromfile","-o","-out","-w","-textOut","-textout","-srcfile","-sep","-d","-dateformat","-dateFormat","-charset","-config"]);let s=0;for(;s<t.length;){const r=t[s];if(r==="--"){i.push(...t.slice(s+1));break}if(r.startsWith("-")){o.push(r);const a=r.toLowerCase().split("=")[0];c.has(a)&&!r.includes("=")&&s+1<t.length&&(s++,o.push(t[s]))}else i.push(r);s++}return{flags:o,filePaths:i}}function w(){console.log(`wexiftool - ExifTool running on WebAssembly
|
|
2
|
+
"use strict";const p=require("fs"),h=require("node:fs/promises"),T=require("node:crypto"),O=require("path"),x=require("./wexiftool-e6N3ift5.cjs"),S=/^-(?:@|c|d|i|o|x|p-?|w[+!]?|W[+!]?)$/,P=new RegExp("^-(?:"+["api","charset","config","coordformat","csvdelim","dateformat","diff","echo\\d*","efile\\d*!?","exclude","ext(?:ension)?\\+?","fileorder\\d*","geotag","globaltimeshift","if\\d*","ignore","lang","listitem","out","password","printformat-?","sep(?:arator)?","srcfile","stay_open","tagout[+!]?","tagsfromfile","textout[+!]?","use","userparam","wm","writemode"].join("|")+")$","i"),b=/^-(?:charset|lang)$/i;function I(s){return S.test(s)||P.test(s)}const v=/^-(?:@|o|out|w[+!]?|textout[+!]?|tagout[+!]?|tagsfromfile|geotag|delete_original!?|restore_original|overwrite_original(?:_in_place)?)$/i;function N(s){return/[=<>]/.test(s)||v.test(s)}const A=/^-(?:tagsfromfile|config|geotag|diff)$/i,R=/^-(?:p-?|printformat-?)$/i,W=/^-(?:csv|j|json)\+?=(.+)$|^-geotag=(.+)$/i,F=/^-(?:o|out)$/i,m=/^-(?:w|textout|tagout)[+!]?$/i,U=/^-(?:efile\d*!?|srcfile|stay_open)$/i;function L(s,a){const e={flags:[],filePaths:[],writes:!1,reads:[],maybeReads:[],outputs:[]},o=t=>{e.unsupported??(e.unsupported=t)},c=[...s];let l=0,i=0;for(;i<c.length;){const t=c[i];if(t==="--"){e.filePaths.push(...c.slice(i+1));break}if(t==="-@"&&a&&i+1<c.length){if(++l>100){o("-@: too many argfiles (one may include itself)");break}c.splice(i,2,...j(a(c[i+1])));continue}if(t.startsWith("-")){e.flags.push(t),e.writes||(e.writes=N(t));const u=W.exec(t);u&&e.reads.push(u[1]??u[2]),U.test(t)&&o(`${t} is not supported by wexiftool`);const n=c[i+1];n!==void 0&&I(t)&&!(b.test(t)&&n.startsWith("-"))&&(i++,e.flags.push(n),A.test(t)&&n!=="@"&&e.reads.push(n),R.test(t)&&e.maybeReads.push(n),F.test(t)&&(n==="-"||n.includes("%")?o(`${t} ${n}: wexiftool supports -o with a file or directory, not stdout or format codes`):e.outputs.push(n)),m.test(t)&&n.replace(/^%[-+]?\d*(?:\.\d+)?d/,"").includes("/")&&o(`${t} ${n}: wexiftool can only create these files in each input's own directory`))}else e.filePaths.push(t);i++}return e.outputs.length>0&&e.flags.some(t=>m.test(t))&&o("-o and -w can not be used together in wexiftool"),e}function j(s){const a=[];for(const e of s.replace(/^/,"").split(new RegExp("(?<=\\n)"))){let o=e;if(o.startsWith("#")){if(!o.startsWith("#[CSTR]"))continue;o=o.slice(7).replace(/[\r\n]+$/,""),o=o.replace(/\\(.)|(["$@]|\\$)/gs,(l,i,t)=>"\\"+(t||i));const c={a:"\x07",b:"\b",f:"\f",n:`
|
|
3
|
+
`,r:"\r",t:" ",'"':'"',"\\":"\\"};o=o.replace(/\\(.)/gs,(l,i)=>c[i]||"\\"+i)}else if(o=o.replace(/^\s+/,"").replace(/[\r\n]+$/,"").replace(/^(-[-_0-9A-Z:]+#?)\s*([-+<]?=) ?/i,"$1$2"),o==="")continue;a.push(o)}return a}async function q(){const s=process.argv.slice(2);s.length===0&&(V(),process.exit(1));const{flags:a,filePaths:e,writes:o,reads:c,maybeReads:l,outputs:i,unsupported:t}=L(s,C);if(t&&(console.error(`Error: ${t}`),process.exit(1)),a.includes("-ver")||a.includes("-version")){const r=await x.WExifTool.create(),f=await r.exec([...a]);r.destroy(),await $(f.stdout,f.stderr,f.exitCode);return}e.length===0&&(console.error("Error: No input files specified."),process.exit(1));for(const r of e){const f=O.resolve(r);p.existsSync(f)||(console.error(`Error: File not found: ${r}`),process.exit(1)),p.statSync(f).isFile()||(console.error(`Error: Not a file: ${r}`),process.exit(1))}const u=await x.WExifTool.create(),n=new Map(e.map(r=>[r,r]));for(const r of[...c,...l])!n.has(r)&&k(r)&&n.set(r,r);const d=[...a,...e];o&&!a.some(r=>/^-overwrite_original(_in_place)?$/i.test(r))&&d.splice(/^-config$/i.test(d[0])?2:0,0,"-overwrite_original");const _=o&&i.length===0?e:[],g=await u.exec(d,n,{writeBack:_,outputs:i});for(const[r,f]of g.files){const w=`${r}.wexiftool_${T.randomBytes(8).toString("hex")}`,{mode:y}=p.statSync(r);try{await h.writeFile(w,f,{flag:"wx",mode:y&4095}),await h.rename(w,r)}catch(E){throw await h.rm(w,{force:!0}),E}}u.destroy(),await $(g.stdout,g.stderr,g.exitCode)}function k(s){try{return p.statSync(s).isFile()}catch{return!1}}function C(s){try{return p.readFileSync(s==="-"?0:s,"utf8")}catch{console.error(`Error opening arg file ${s}`),process.exit(1)}}async function $(s,a,e){const o=(c,l)=>new Promise(i=>{if(!l)return i();c.write(l+`
|
|
4
|
+
`,()=>i())});await o(process.stdout,s),await o(process.stderr,a),process.exit(e)}function V(){console.log(`wexiftool - ExifTool running on WebAssembly
|
|
7
5
|
|
|
8
6
|
Usage:
|
|
9
7
|
wexiftool [OPTIONS] FILE...
|
|
@@ -16,4 +14,4 @@ Examples:
|
|
|
16
14
|
wexiftool -ver Show ExifTool version
|
|
17
15
|
|
|
18
16
|
All standard ExifTool options are supported.
|
|
19
|
-
See https://exiftool.org/ for full documentation.`)}
|
|
17
|
+
See https://exiftool.org/ for full documentation.`)}q().catch(s=>{console.error(s.message||s),process.exit(1)});
|
package/dist/cli.es.js
CHANGED
|
@@ -1,66 +1,152 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { existsSync as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
2
|
+
import { existsSync as E, statSync as w, readFileSync as O } from "fs";
|
|
3
|
+
import { writeFile as T, rename as P, rm as S } from "node:fs/promises";
|
|
4
|
+
import { randomBytes as b } from "node:crypto";
|
|
5
|
+
import { resolve as I } from "path";
|
|
6
|
+
import { W as h } from "./wexiftool-CRI8zlju.js";
|
|
7
|
+
const v = /^-(?:@|c|d|i|o|x|p-?|w[+!]?|W[+!]?)$/, N = new RegExp(
|
|
8
|
+
"^-(?:" + [
|
|
9
|
+
"api",
|
|
10
|
+
"charset",
|
|
11
|
+
"config",
|
|
12
|
+
"coordformat",
|
|
13
|
+
"csvdelim",
|
|
14
|
+
"dateformat",
|
|
15
|
+
"diff",
|
|
16
|
+
"echo\\d*",
|
|
17
|
+
"efile\\d*!?",
|
|
18
|
+
"exclude",
|
|
19
|
+
"ext(?:ension)?\\+?",
|
|
20
|
+
"fileorder\\d*",
|
|
21
|
+
"geotag",
|
|
22
|
+
"globaltimeshift",
|
|
23
|
+
"if\\d*",
|
|
24
|
+
"ignore",
|
|
25
|
+
"lang",
|
|
26
|
+
"listitem",
|
|
27
|
+
"out",
|
|
28
|
+
"password",
|
|
29
|
+
"printformat-?",
|
|
30
|
+
"sep(?:arator)?",
|
|
31
|
+
"srcfile",
|
|
32
|
+
"stay_open",
|
|
33
|
+
"tagout[+!]?",
|
|
34
|
+
"tagsfromfile",
|
|
35
|
+
"textout[+!]?",
|
|
36
|
+
"use",
|
|
37
|
+
"userparam",
|
|
38
|
+
"wm",
|
|
39
|
+
"writemode"
|
|
40
|
+
].join("|") + ")$",
|
|
41
|
+
"i"
|
|
42
|
+
), A = /^-(?:charset|lang)$/i;
|
|
43
|
+
function R(s) {
|
|
44
|
+
return v.test(s) || N.test(s);
|
|
28
45
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
"-charset",
|
|
44
|
-
"-config"
|
|
45
|
-
]);
|
|
46
|
-
let s = 0;
|
|
47
|
-
for (; s < t.length; ) {
|
|
48
|
-
const r = t[s];
|
|
49
|
-
if (r === "--") {
|
|
50
|
-
i.push(...t.slice(s + 1));
|
|
46
|
+
const W = /^-(?:@|o|out|w[+!]?|textout[+!]?|tagout[+!]?|tagsfromfile|geotag|delete_original!?|restore_original|overwrite_original(?:_in_place)?)$/i;
|
|
47
|
+
function F(s) {
|
|
48
|
+
return /[=<>]/.test(s) || W.test(s);
|
|
49
|
+
}
|
|
50
|
+
const U = /^-(?:tagsfromfile|config|geotag|diff)$/i, L = /^-(?:p-?|printformat-?)$/i, j = /^-(?:csv|j|json)\+?=(.+)$|^-geotag=(.+)$/i, k = /^-(?:o|out)$/i, m = /^-(?:w|textout|tagout)[+!]?$/i, C = /^-(?:efile\d*!?|srcfile|stay_open)$/i;
|
|
51
|
+
function V(s, a) {
|
|
52
|
+
const t = { flags: [], filePaths: [], writes: !1, reads: [], maybeReads: [], outputs: [] }, o = (e) => {
|
|
53
|
+
t.unsupported ?? (t.unsupported = e);
|
|
54
|
+
}, c = [...s];
|
|
55
|
+
let l = 0, i = 0;
|
|
56
|
+
for (; i < c.length; ) {
|
|
57
|
+
const e = c[i];
|
|
58
|
+
if (e === "--") {
|
|
59
|
+
t.filePaths.push(...c.slice(i + 1));
|
|
51
60
|
break;
|
|
52
61
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
if (e === "-@" && a && i + 1 < c.length) {
|
|
63
|
+
if (++l > 100) {
|
|
64
|
+
o("-@: too many argfiles (one may include itself)");
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
c.splice(i, 2, ...B(a(c[i + 1])));
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (e.startsWith("-")) {
|
|
71
|
+
t.flags.push(e), t.writes || (t.writes = F(e));
|
|
72
|
+
const u = j.exec(e);
|
|
73
|
+
u && t.reads.push(u[1] ?? u[2]), C.test(e) && o(`${e} is not supported by wexiftool`);
|
|
74
|
+
const n = c[i + 1];
|
|
75
|
+
n !== void 0 && R(e) && !(A.test(e) && n.startsWith("-")) && (i++, t.flags.push(n), U.test(e) && n !== "@" && t.reads.push(n), L.test(e) && t.maybeReads.push(n), k.test(e) && (n === "-" || n.includes("%") ? o(`${e} ${n}: wexiftool supports -o with a file or directory, not stdout or format codes`) : t.outputs.push(n)), m.test(e) && n.replace(/^%[-+]?\d*(?:\.\d+)?d/, "").includes("/") && o(`${e} ${n}: wexiftool can only create these files in each input's own directory`));
|
|
57
76
|
} else
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
t.filePaths.push(e);
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
return t.outputs.length > 0 && t.flags.some((e) => m.test(e)) && o("-o and -w can not be used together in wexiftool"), t;
|
|
81
|
+
}
|
|
82
|
+
function B(s) {
|
|
83
|
+
const a = [];
|
|
84
|
+
for (const t of s.replace(/^/, "").split(new RegExp("(?<=\\n)"))) {
|
|
85
|
+
let o = t;
|
|
86
|
+
if (o.startsWith("#")) {
|
|
87
|
+
if (!o.startsWith("#[CSTR]")) continue;
|
|
88
|
+
o = o.slice(7).replace(/[\r\n]+$/, ""), o = o.replace(/\\(.)|(["$@]|\\$)/gs, (l, i, e) => "\\" + (e || i));
|
|
89
|
+
const c = { a: "\x07", b: "\b", f: "\f", n: `
|
|
90
|
+
`, r: "\r", t: " ", '"': '"', "\\": "\\" };
|
|
91
|
+
o = o.replace(/\\(.)/gs, (l, i) => c[i] || "\\" + i);
|
|
92
|
+
} else if (o = o.replace(/^\s+/, "").replace(/[\r\n]+$/, "").replace(/^(-[-_0-9A-Z:]+#?)\s*([-+<]?=) ?/i, "$1$2"), o === "") continue;
|
|
93
|
+
a.push(o);
|
|
94
|
+
}
|
|
95
|
+
return a;
|
|
96
|
+
}
|
|
97
|
+
async function D() {
|
|
98
|
+
const s = process.argv.slice(2);
|
|
99
|
+
s.length === 0 && (M(), process.exit(1));
|
|
100
|
+
const { flags: a, filePaths: t, writes: o, reads: c, maybeReads: l, outputs: i, unsupported: e } = V(s, J);
|
|
101
|
+
if (e && (console.error(`Error: ${e}`), process.exit(1)), a.includes("-ver") || a.includes("-version")) {
|
|
102
|
+
const r = await h.create(), f = await r.exec([...a]);
|
|
103
|
+
r.destroy(), await x(f.stdout, f.stderr, f.exitCode);
|
|
104
|
+
return;
|
|
60
105
|
}
|
|
61
|
-
|
|
106
|
+
t.length === 0 && (console.error("Error: No input files specified."), process.exit(1));
|
|
107
|
+
for (const r of t) {
|
|
108
|
+
const f = I(r);
|
|
109
|
+
E(f) || (console.error(`Error: File not found: ${r}`), process.exit(1)), w(f).isFile() || (console.error(`Error: Not a file: ${r}`), process.exit(1));
|
|
110
|
+
}
|
|
111
|
+
const u = await h.create(), n = new Map(t.map((r) => [r, r]));
|
|
112
|
+
for (const r of [...c, ...l])
|
|
113
|
+
!n.has(r) && G(r) && n.set(r, r);
|
|
114
|
+
const g = [...a, ...t];
|
|
115
|
+
o && !a.some((r) => /^-overwrite_original(_in_place)?$/i.test(r)) && g.splice(/^-config$/i.test(g[0]) ? 2 : 0, 0, "-overwrite_original");
|
|
116
|
+
const $ = o && i.length === 0 ? t : [], p = await u.exec(g, n, { writeBack: $, outputs: i });
|
|
117
|
+
for (const [r, f] of p.files) {
|
|
118
|
+
const d = `${r}.wexiftool_${b(8).toString("hex")}`, { mode: _ } = w(r);
|
|
119
|
+
try {
|
|
120
|
+
await T(d, f, { flag: "wx", mode: _ & 4095 }), await P(d, r);
|
|
121
|
+
} catch (y) {
|
|
122
|
+
throw await S(d, { force: !0 }), y;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
u.destroy(), await x(p.stdout, p.stderr, p.exitCode);
|
|
126
|
+
}
|
|
127
|
+
function G(s) {
|
|
128
|
+
try {
|
|
129
|
+
return w(s).isFile();
|
|
130
|
+
} catch {
|
|
131
|
+
return !1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function J(s) {
|
|
135
|
+
try {
|
|
136
|
+
return O(s === "-" ? 0 : s, "utf8");
|
|
137
|
+
} catch {
|
|
138
|
+
console.error(`Error opening arg file ${s}`), process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async function x(s, a, t) {
|
|
142
|
+
const o = (c, l) => new Promise((i) => {
|
|
143
|
+
if (!l) return i();
|
|
144
|
+
c.write(l + `
|
|
145
|
+
`, () => i());
|
|
146
|
+
});
|
|
147
|
+
await o(process.stdout, s), await o(process.stderr, a), process.exit(t);
|
|
62
148
|
}
|
|
63
|
-
function
|
|
149
|
+
function M() {
|
|
64
150
|
console.log(`wexiftool - ExifTool running on WebAssembly
|
|
65
151
|
|
|
66
152
|
Usage:
|
|
@@ -76,6 +162,6 @@ Examples:
|
|
|
76
162
|
All standard ExifTool options are supported.
|
|
77
163
|
See https://exiftool.org/ for full documentation.`);
|
|
78
164
|
}
|
|
79
|
-
|
|
80
|
-
console.error(
|
|
165
|
+
D().catch((s) => {
|
|
166
|
+
console.error(s.message || s), process.exit(1);
|
|
81
167
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var V = Object.defineProperty;
|
|
2
2
|
var Y = (e, t, n) => t in e ? V(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
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-
|
|
4
|
+
import { a as b, b as $, c as z, d as H, e as D, f as I, g as L } from "./wexiftool-CRI8zlju.js";
|
|
5
5
|
function q(e) {
|
|
6
6
|
if (!e.startsWith("/") || e === "/" || e.endsWith("/"))
|
|
7
7
|
throw new b(`mountpoint must be an absolute path other than "/", without a trailing slash: ${e}`);
|
|
@@ -646,7 +646,7 @@ async function bt(e, t, n = {}) {
|
|
|
646
646
|
if (l === "memfs")
|
|
647
647
|
return P(e, t, s);
|
|
648
648
|
if (l === "node") {
|
|
649
|
-
const { openNodeBackend: f } = await import("./node-
|
|
649
|
+
const { openNodeBackend: f } = await import("./node-Cu1famID.js");
|
|
650
650
|
return v(e, t, await f(s));
|
|
651
651
|
}
|
|
652
652
|
if (l !== "opfs")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var j=Object.defineProperty;var B=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var O=(e,t,n)=>B(e,typeof t!="symbol"?t+"":t,n);const p=require("./wexiftool-Dt9AnMsh.cjs");function L(e){if(!e.startsWith("/")||e==="/"||e.endsWith("/"))throw new p.WopfsInputError(`mountpoint must be an absolute path other than "/", without a trailing slash: ${e}`)}function q(e){if(e.split("/").some(n=>n===""||n==="."||n===".."))throw new p.WopfsInputError(`input path must be relative and normalized: ${JSON.stringify(e)}`)}function P(e,t){const n=e.analyzePath(t);if(n.exists){if(!n.object||!e.isDir(n.object.mode))throw new p.WopfsInputError(`${t} exists and is not a directory`);return[]}const r=t.split("/").slice(1),a=r.map((f,l)=>"/"+r.slice(0,l+1).join("/")).filter(f=>!e.analyzePath(f).exists);return e.mkdirTree(t),a}function k(e,t){for(const n of[...t].reverse())e.rmdir(n)}function I(e,t){for(const n of e.streams)if(n&&n.node.mount===t)try{e.close(n)}catch{}}function U(e,t){return(t==null?void 0:t.name)==="ErrnoError"?new p.WopfsInputError(`cannot mount at ${e} (errno ${t.errno}); is it already a mount point?`,{cause:t}):t}function v(e,t,n,r){I(e,n);const a=r[0]??t,f=e.cwd();(f===a||f.startsWith(`${a}/`))&&e.chdir(a.slice(0,a.lastIndexOf("/"))||"/");try{e.unmount(t)}catch(l){const h=l==null?void 0:l.errno;throw new p.WopfsStateError(`cannot unmount ${t} (errno ${h}); release() can be retried`,{cause:l})}k(e,r)}function H(){var r,a;const e=globalThis;if((a=(r=e.process)==null?void 0:r.versions)!=null&&a.node&&typeof e.window>"u")return"node";const t=e.DedicatedWorkerGlobalScope,n=e.FileSystemFileHandle;return typeof t=="function"&&globalThis instanceof t&&n&&"createSyncAccessHandle"in n.prototype?"opfs":"memfs"}const J=["ErrnoError","createNode","hashRemoveNode","isDir","isFile","mount","unmount","lookupPath","analyzePath","mkdirTree","rmdir","readdir","writeFile","readFile","chmod","close","cwd","chdir"];function V(e){var r;const t=e==null?void 0:e.FS;if(!t)throw new p.WopfsRuntimeError("module has no FS export; build it with -sEXPORTED_RUNTIME_METHODS=FS");const n=J.filter(a=>typeof t[a]!="function");if(Array.isArray(t.streams)||n.push("streams"),(r=t.filesystems)!=null&&r.MEMFS||n.push("filesystems.MEMFS"),n.length)throw new p.WopfsRuntimeError(`module.FS is missing ${n.join(", ")}: this Emscripten's FS internals differ from the ones wopfs supports (emsdk 5.0.5, 5.0.6)`)}const b={EACCES:2,EINVAL:28,EIO:29,ENODEV:43,ENOENT:44,ENOSPC:51,ENOTEMPTY:55,EPERM:63,EROFS:69},Y=0,K=1,Q=2,G=61440,x=16384,X=32768,N=x|511,Z=X|292,g=e=>(e.mode&G)===x;function tt(e){const t=e._malloc;return typeof t!="function"||!e.HEAPU8?()=>null:n=>{const r=t(n);return r?{ptr:r,heap:e.HEAPU8,free:()=>{var a;return(a=e._free)==null?void 0:a.call(e,r)}}:null}}function et(e,t){const n=o=>new e.ErrnoError(o);function r(o){try{return o()}catch(s){const{name:i,code:c}=s??{};throw i==="ErrnoError"?s:n(i==="QuotaExceededError"||c==="ENOSPC"||c==="EDQUOT"?b.ENOSPC:b.EIO)}}const a=o=>o.wopfs;function f(o,s,i,c){const u=e.createNode(o,s,i,0);return u.node_ops=E,u.stream_ops=d,u.atime=u.mtime=u.ctime=Date.now(),g(u)?u.contents=Object.create(null):u.wopfs=c,o&&(o.contents[s]=u,o.mtime=o.ctime=u.mtime),u}function l(o){const s=o.wopfs;!s||s.input||(s.unlinked=!0,s.openCount===0&&t.discardFile(s.file))}function h(o){const s=a(o);if(s.input)throw n(b.EACCES);return s}const m=o=>{o.mtime=o.ctime=Date.now()},E={getattr(o){const s=g(o)?4096:a(o).size;return{dev:1,ino:o.id,mode:o.mode,nlink:1,uid:0,gid:0,rdev:0,size:s,atime:new Date(o.atime),mtime:new Date(o.mtime),ctime:new Date(o.ctime),blksize:4096,blocks:Math.ceil(s/4096)}},setattr(o,s){for(const i of["mode","atime","mtime","ctime"])s[i]!=null&&(o[i]=s[i]);if(s.size!==void 0){const i=h(o),c=s.size;r(()=>i.file.truncate(c)),i.size=c,m(o)}},lookup(o,s){const i=o.contents[s];if(i)return i;throw n(b.ENOENT)},mknod(o,s,i){if(t.readOnly)throw n(b.EROFS);if(e.isDir(i))return f(o,s,i);if(!e.isFile(i))throw n(b.EPERM);const c=r(()=>t.createFile());if(!c)throw n(b.ENOSPC);return f(o,s,i,{file:c,size:0,input:!1,openCount:0,unlinked:!1})},rename(o,s,i){const c=s.contents[i];if(c){if(g(c)&&Object.keys(c.contents).length)throw n(b.ENOTEMPTY);e.hashRemoveNode(c),l(c)}delete o.parent.contents[o.name],s.contents[i]=o,o.name=i,m(s),m(o.parent)},unlink(o,s){const i=o.contents[s];delete o.contents[s],m(o),l(i)},rmdir(o,s){const i=o.contents[s];if(Object.keys(i.contents).length)throw n(b.ENOTEMPTY);delete o.contents[s],m(o)},readdir(o){return[".","..",...Object.keys(o.contents)]},symlink(){throw n(b.EPERM)}},d={open(o){if(g(o.node))return;const s=(o.flags&3)===Y?a(o.node):h(o.node);s.openCount++},dup(o){g(o.node)||a(o.node).openCount++},close(o){if(g(o.node))return;const s=a(o.node);s.openCount--,s.unlinked?s.openCount===0&&t.discardFile(s.file):s.input||r(()=>s.file.flush())},read(o,s,i,c,u){const w=a(o.node);if(u>=w.size)return 0;const y=Math.min(c,w.size-u);return r(()=>w.file.read(new Uint8Array(s.buffer,s.byteOffset+i,y),u))},write(o,s,i,c,u){if(!c)return 0;const w=h(o.node),y=r(()=>w.file.write(new Uint8Array(s.buffer,s.byteOffset+i,c),u));return w.size=Math.max(w.size,u+y),m(o.node),y},llseek(o,s,i){let c=s;if(i===K?c+=o.position:i===Q&&!g(o.node)&&(c+=a(o.node).size),c<0)throw n(b.EINVAL);return c},mmap(o,s,i){if(g(o.node))throw n(b.ENODEV);const c=t.mmapAlloc(s);if(!c)throw n(b.ENODEV);const u=c.heap.subarray(c.ptr,c.ptr+s),w=a(o.node),y=i<w.size?Math.min(s,w.size-i):0;if(y)try{r(()=>w.file.read(u.subarray(0,y),i))}catch(W){throw c.free(),W}return u.fill(0,y),{ptr:c.ptr,allocated:!0}},msync(o,s,i,c){return d.write(o,s,0,c,i),0},fsync(o){return g(o.node)||r(()=>a(o.node).file.flush()),0}};return{mount(o){const s=f(null,"/",N);s.mount=o;for(const{path:i,file:c}of o.opts.inputs??[]){const u=i.split("/");let w=s;for(const y of u.slice(0,-1))w=w.contents[y]??f(w,y,N);f(w,u[u.length-1],Z,{file:c,size:c.getSize(),input:!0,openCount:0,unlinked:!1})}return s},node_ops:E,stream_ops:d}}function nt(e){const t=[],n=(r,a)=>{for(const[f,l]of Object.entries(r.contents)){const h=a?`${a}/${f}`:f;g(l)?n(l,h):l.wopfs&&!l.wopfs.input&&t.push({path:h,backing:l.wopfs})}};return n(e,""),t.sort((r,a)=>r.path<a.path?-1:r.path>a.path?1:0)}class M{constructor(t){O(this,"data");O(this,"size");this.data=t??new Uint8Array(0),this.size=this.data.length}read(t,n){const r=Math.max(0,Math.min(t.length,this.size-n));return t.set(this.data.subarray(n,n+r)),r}write(t,n){const r=n+t.length;return this.reserve(r),n>this.size&&this.data.fill(0,this.size,n),this.data.set(t,n),this.size=Math.max(this.size,r),t.length}truncate(t){t>this.size&&(this.reserve(t),this.data.fill(0,this.size,t)),this.size=t}getSize(){return this.size}flush(){}close(){}bytes(){return this.data.subarray(0,this.size)}reserve(t){if(t<=this.data.length)return;const n=new Uint8Array(Math.max(t,this.data.length*2,4096));n.set(this.data.subarray(0,this.size)),this.data=n}}function rt(e){let t=!1;return{read:(n,r)=>e.read(n,{at:r}),write:(n,r)=>e.write(n,{at:r}),truncate:n=>e.truncate(n),getSize:()=>e.getSize(),flush:()=>e.flush(),close:()=>{t||(t=!0,e.close())}}}const ot=1<<20;function st(e,t,n){const r=new Uint8Array(Math.min(ot,Math.max(n,1)));t.truncate(0);for(let a=0;a<n;){const f=e.read(r.subarray(0,Math.min(r.length,n-a)),a);if(f<=0)break;t.write(r.subarray(0,f),a),a+=f}}class D{constructor(t){O(this,"options");O(this,"slots");O(this,"free");O(this,"byFile",new Map);O(this,"warned",!1);this.options=t,this.slots=[...t.preopened??[]],this.free=[...this.slots].reverse();for(const n of this.slots)this.byFile.set(n.file,n)}acquire(){let t=this.free.pop();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 M)}discard(t){const n=this.byFile.get(t);if(n){try{t.truncate(0)}catch{return}this.free.push(n)}}slotOf(t){return this.byFile.get(t)}}function it(e,t,n){const r=e.FS,a=P(r,t),f=et(r,{createFile:()=>n.pool.acquire(),discardFile:m=>n.pool.discard(m),mmapAlloc:tt(e),readOnly:n.readOnly});let l;try{l=r.mount(f,{inputs:n.inputs},t)}catch(m){throw k(r,a),U(t,m)}let h="mounted";return{backend:n.kind,mountpoint:t,async commit(){if(h!=="mounted")throw new p.WopfsStateError(`commit() on a mount that is ${h}`);h="committing",I(r,l.mount);for(const{file:E}of n.inputs)E.close();const m=[];try{for(const{path:E,backing:d}of nt(l))m.push(await n.commitFile(E,d.file,d.size))}catch(E){throw new p.WopfsCommitError(m,E)}return h="committed",m},async release(){if(h!=="released"){h="releasing";try{v(r,t,l.mount,a)}finally{await n.release()}h="released"}}}}function T(e,t,n){return{kind:e,inputs:t,readOnly:!0,pool:new D({capacity:0,onExhausted:"strict",warn:()=>{}}),async commitFile(r){throw new p.WopfsStateError(`an input-only mount (no outputDir) cannot commit ${r}`)},release:n}}function _(e){return typeof e=="object"&&e!==null&&e.kind==="file"&&typeof e.getFile=="function"}function at(e){return typeof e=="object"&&e!==null&&e.kind==="directory"&&typeof e.getFileHandle=="function"}const ct={opfs:"a FileSystemFileHandle, Uint8Array or Blob",node:"a host path string, Uint8Array or Blob",memfs:"a Uint8Array, Blob or FileSystemFileHandle"};async function z(e,t,n){if(e instanceof Uint8Array)return e;if(typeof Blob<"u"&&e instanceof Blob)return new Uint8Array(await e.arrayBuffer());if(n==="memfs"&&_(e))return new Uint8Array(await(await e.getFile()).arrayBuffer());throw new p.WopfsInputError(`input ${t}: the ${n} backend takes ${ct[n]}`)}function R(){return globalThis.crypto.randomUUID().slice(0,8)}async function $(e,t){let n;try{n=await e.createSyncAccessHandle()}catch(r){const a=r==null?void 0:r.name;throw a==="NoModificationAllowedError"||a==="InvalidStateError"?new p.WopfsLockedError(t,r):r}if(typeof n.getSize()!="number")throw await n.close(),new p.WopfsUnsupportedError("this browser's FileSystemSyncAccessHandle methods are asynchronous; wopfs needs the synchronous ones");return rt(n)}async function ft(e,t,n){try{await e.move(t,n)}catch(r){if((r==null?void 0:r.name)!=="InvalidModificationError")throw r;await t.removeEntry(n),await e.move(t,n)}}async function lt(e,t,n,r,a){const f=await $(t,n);try{st(e,f,r),f.flush()}catch(l){throw f.close(),await a().catch(()=>{}),l}f.close()}async function ut(e){const t=e.outputDir;if(t!==void 0&&!at(t))throw new p.WopfsInputError("the opfs backend needs outputDir to be a FileSystemDirectoryHandle");if(t===void 0&&e.scratch>0)throw new p.WopfsInputError(`scratch (${e.scratch}) needs outputDir: without it the mount is input-only`);const n=[],r=`.wopfs-scratch-${R()}`;let a,f=0;const l=async()=>{for(const h of n)try{h.close()}catch{}a&&await t.removeEntry(r,{recursive:!0}).catch(()=>{})};try{const h=[],m=[];for(const[s,i]of e.inputs)if(_(i)){for(const[u,w]of m)if(await w.isSameEntry(i))throw new p.WopfsInputError(`inputs ${JSON.stringify(u)} and ${JSON.stringify(s)} are the same file`);m.push([s,i]);const c=await $(i,s);n.push(c),h.push({path:s,file:c})}else h.push({path:s,file:new M(await z(i,s,"opfs"))});if(t===void 0)return T("opfs",h,l);if(a=await t.getDirectoryHandle(r,{create:!0}),typeof(await a.getFileHandle("probe",{create:!0})).move!="function")throw new p.WopfsUnsupportedError("this browser's FileSystemFileHandle has no move(); wopfs needs it to commit outputs safely");const d=[];for(let s=0;s<e.scratch;s++){const i=`s${s}`,c=await a.getFileHandle(i,{create:!0}),u=await $(c,`${r}/${i}`);n.push(u),d.push({name:i,file:u,handle:c})}const o=new D({capacity:e.scratch,onExhausted:e.onExhausted,preopened:d,warn:e.warn});return{kind:"opfs",inputs:h,pool:o,async commitFile(s,i,c){const u=s.split("/"),w=u.pop();let y=t;for(const F of u)y=await y.getDirectoryHandle(F,{create:!0});const W=o.slotOf(i);let S;if(W)i.flush(),i.close(),S=W.handle;else{const F=`spill${f++}`;S=await a.getFileHandle(F,{create:!0}),await lt(i,S,`${r}/${F}`,c,()=>a.removeEntry(F)),i.close()}return await ft(S,y,w),{path:s,size:c,handle:S}},release:l}}catch(h){throw await l(),h}}async function A(e,t,n){const r=e.FS,a=[];for(const[d,o]of n.inputs)a.push([d,await z(o,d,"memfs")]);const f=P(r,t);let l;try{l=r.mount(r.filesystems.MEMFS,{},t)}catch(d){throw k(r,f),U(t,d)}const h=new Set;try{for(const[d,o]of a){const s=`${t}/${d}`;r.mkdirTree(s.slice(0,s.lastIndexOf("/"))),r.writeFile(s,o),r.chmod(s,292),h.add(r.lookupPath(s).node)}}catch(d){throw r.unmount(t),k(r,f),d}const m=(d,o,s)=>{for(const i of r.readdir(d)){if(i==="."||i==="..")continue;const c=`${d}/${i}`,u=o?`${o}/${i}`:i,w=r.lookupPath(c).node;if(r.isDir(w.mode))m(c,u,s);else if(r.isFile(w.mode)&&!h.has(w)){const y=r.readFile(c);s.push({path:u,size:y.length,bytes:y})}}};let E="mounted";return{backend:"memfs",mountpoint:t,async commit(){if(E!=="mounted")throw new p.WopfsStateError(`commit() on a mount that is ${E}`);I(r,l.mount);const d=[];return m(t,"",d),E="committed",d.sort((o,s)=>o.path<s.path?-1:o.path>s.path?1:0)},async release(){E!=="released"&&(E="releasing",v(r,t,l.mount,f),E="released")}}}function ht(e){const t=Object.entries(e.inputs??{});for(const[f]of t)q(f);const n=new Set(t.map(([f])=>f));for(const[f]of t){const l=f.split("/");for(let h=1;h<l.length;h++){const m=l.slice(0,h).join("/");if(n.has(m))throw new p.WopfsInputError(`input ${JSON.stringify(m)} is a file, but ${JSON.stringify(f)} needs it to be a directory`)}}const r=e.scratch??(e.outputDir===void 0?0:16);if(!Number.isInteger(r)||r<0)throw new p.WopfsInputError(`scratch must be a non-negative integer: ${r}`);const a=e.onExhausted??"spill";if(a!=="spill"&&a!=="strict")throw new p.WopfsInputError(`onExhausted must be "spill" or "strict": ${a}`);return{inputs:t,outputDir:e.outputDir,scratch:r,onExhausted:a,warn:e.onWarning??(f=>console.warn(f))}}async function C(e,t,n){try{return it(e,t,n)}catch(r){throw await n.release(),r}}async function pt(e,t,n={}){V(e),L(t);const r=ht(n),a=n.backend??"auto",f=a==="auto"?H():a;if(f==="memfs")return A(e,t,r);if(f==="node"){const{openNodeBackend:l}=await Promise.resolve().then(()=>require("./node-6KJNNt7l.cjs"));return C(e,t,await l(r))}if(f!=="opfs")throw new p.WopfsInputError(`unknown backend: ${String(f)}`);try{return await C(e,t,await ut(r))}catch(l){if(a==="auto"&&l instanceof p.WopfsUnsupportedError)return r.warn(`wopfs: ${l.message}; falling back to memfs`),A(e,t,r);throw l}}const dt=Object.freeze(Object.defineProperty({__proto__:null,WopfsCommitError:p.WopfsCommitError,WopfsError:p.WopfsError,WopfsInputError:p.WopfsInputError,WopfsLockedError:p.WopfsLockedError,WopfsRuntimeError:p.WopfsRuntimeError,WopfsStateError:p.WopfsStateError,WopfsUnsupportedError:p.WopfsUnsupportedError,detectBackend:H,mountFiles:pt},Symbol.toStringTag,{value:"Module"}));exports.MemoryFile=M;exports.ScratchPool=D;exports.bytesOf=z;exports.index=dt;exports.inputOnlyBackend=T;exports.randomId=R;
|
|
1
|
+
"use strict";var j=Object.defineProperty;var B=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var O=(e,t,n)=>B(e,typeof t!="symbol"?t+"":t,n);const p=require("./wexiftool-e6N3ift5.cjs");function L(e){if(!e.startsWith("/")||e==="/"||e.endsWith("/"))throw new p.WopfsInputError(`mountpoint must be an absolute path other than "/", without a trailing slash: ${e}`)}function q(e){if(e.split("/").some(n=>n===""||n==="."||n===".."))throw new p.WopfsInputError(`input path must be relative and normalized: ${JSON.stringify(e)}`)}function P(e,t){const n=e.analyzePath(t);if(n.exists){if(!n.object||!e.isDir(n.object.mode))throw new p.WopfsInputError(`${t} exists and is not a directory`);return[]}const r=t.split("/").slice(1),a=r.map((f,l)=>"/"+r.slice(0,l+1).join("/")).filter(f=>!e.analyzePath(f).exists);return e.mkdirTree(t),a}function k(e,t){for(const n of[...t].reverse())e.rmdir(n)}function I(e,t){for(const n of e.streams)if(n&&n.node.mount===t)try{e.close(n)}catch{}}function U(e,t){return(t==null?void 0:t.name)==="ErrnoError"?new p.WopfsInputError(`cannot mount at ${e} (errno ${t.errno}); is it already a mount point?`,{cause:t}):t}function v(e,t,n,r){I(e,n);const a=r[0]??t,f=e.cwd();(f===a||f.startsWith(`${a}/`))&&e.chdir(a.slice(0,a.lastIndexOf("/"))||"/");try{e.unmount(t)}catch(l){const h=l==null?void 0:l.errno;throw new p.WopfsStateError(`cannot unmount ${t} (errno ${h}); release() can be retried`,{cause:l})}k(e,r)}function H(){var r,a;const e=globalThis;if((a=(r=e.process)==null?void 0:r.versions)!=null&&a.node&&typeof e.window>"u")return"node";const t=e.DedicatedWorkerGlobalScope,n=e.FileSystemFileHandle;return typeof t=="function"&&globalThis instanceof t&&n&&"createSyncAccessHandle"in n.prototype?"opfs":"memfs"}const J=["ErrnoError","createNode","hashRemoveNode","isDir","isFile","mount","unmount","lookupPath","analyzePath","mkdirTree","rmdir","readdir","writeFile","readFile","chmod","close","cwd","chdir"];function V(e){var r;const t=e==null?void 0:e.FS;if(!t)throw new p.WopfsRuntimeError("module has no FS export; build it with -sEXPORTED_RUNTIME_METHODS=FS");const n=J.filter(a=>typeof t[a]!="function");if(Array.isArray(t.streams)||n.push("streams"),(r=t.filesystems)!=null&&r.MEMFS||n.push("filesystems.MEMFS"),n.length)throw new p.WopfsRuntimeError(`module.FS is missing ${n.join(", ")}: this Emscripten's FS internals differ from the ones wopfs supports (emsdk 5.0.5, 5.0.6)`)}const b={EACCES:2,EINVAL:28,EIO:29,ENODEV:43,ENOENT:44,ENOSPC:51,ENOTEMPTY:55,EPERM:63,EROFS:69},Y=0,K=1,Q=2,G=61440,x=16384,X=32768,N=x|511,Z=X|292,g=e=>(e.mode&G)===x;function tt(e){const t=e._malloc;return typeof t!="function"||!e.HEAPU8?()=>null:n=>{const r=t(n);return r?{ptr:r,heap:e.HEAPU8,free:()=>{var a;return(a=e._free)==null?void 0:a.call(e,r)}}:null}}function et(e,t){const n=o=>new e.ErrnoError(o);function r(o){try{return o()}catch(s){const{name:i,code:c}=s??{};throw i==="ErrnoError"?s:n(i==="QuotaExceededError"||c==="ENOSPC"||c==="EDQUOT"?b.ENOSPC:b.EIO)}}const a=o=>o.wopfs;function f(o,s,i,c){const u=e.createNode(o,s,i,0);return u.node_ops=E,u.stream_ops=d,u.atime=u.mtime=u.ctime=Date.now(),g(u)?u.contents=Object.create(null):u.wopfs=c,o&&(o.contents[s]=u,o.mtime=o.ctime=u.mtime),u}function l(o){const s=o.wopfs;!s||s.input||(s.unlinked=!0,s.openCount===0&&t.discardFile(s.file))}function h(o){const s=a(o);if(s.input)throw n(b.EACCES);return s}const m=o=>{o.mtime=o.ctime=Date.now()},E={getattr(o){const s=g(o)?4096:a(o).size;return{dev:1,ino:o.id,mode:o.mode,nlink:1,uid:0,gid:0,rdev:0,size:s,atime:new Date(o.atime),mtime:new Date(o.mtime),ctime:new Date(o.ctime),blksize:4096,blocks:Math.ceil(s/4096)}},setattr(o,s){for(const i of["mode","atime","mtime","ctime"])s[i]!=null&&(o[i]=s[i]);if(s.size!==void 0){const i=h(o),c=s.size;r(()=>i.file.truncate(c)),i.size=c,m(o)}},lookup(o,s){const i=o.contents[s];if(i)return i;throw n(b.ENOENT)},mknod(o,s,i){if(t.readOnly)throw n(b.EROFS);if(e.isDir(i))return f(o,s,i);if(!e.isFile(i))throw n(b.EPERM);const c=r(()=>t.createFile());if(!c)throw n(b.ENOSPC);return f(o,s,i,{file:c,size:0,input:!1,openCount:0,unlinked:!1})},rename(o,s,i){const c=s.contents[i];if(c){if(g(c)&&Object.keys(c.contents).length)throw n(b.ENOTEMPTY);e.hashRemoveNode(c),l(c)}delete o.parent.contents[o.name],s.contents[i]=o,o.name=i,m(s),m(o.parent)},unlink(o,s){const i=o.contents[s];delete o.contents[s],m(o),l(i)},rmdir(o,s){const i=o.contents[s];if(Object.keys(i.contents).length)throw n(b.ENOTEMPTY);delete o.contents[s],m(o)},readdir(o){return[".","..",...Object.keys(o.contents)]},symlink(){throw n(b.EPERM)}},d={open(o){if(g(o.node))return;const s=(o.flags&3)===Y?a(o.node):h(o.node);s.openCount++},dup(o){g(o.node)||a(o.node).openCount++},close(o){if(g(o.node))return;const s=a(o.node);s.openCount--,s.unlinked?s.openCount===0&&t.discardFile(s.file):s.input||r(()=>s.file.flush())},read(o,s,i,c,u){const w=a(o.node);if(u>=w.size)return 0;const y=Math.min(c,w.size-u);return r(()=>w.file.read(new Uint8Array(s.buffer,s.byteOffset+i,y),u))},write(o,s,i,c,u){if(!c)return 0;const w=h(o.node),y=r(()=>w.file.write(new Uint8Array(s.buffer,s.byteOffset+i,c),u));return w.size=Math.max(w.size,u+y),m(o.node),y},llseek(o,s,i){let c=s;if(i===K?c+=o.position:i===Q&&!g(o.node)&&(c+=a(o.node).size),c<0)throw n(b.EINVAL);return c},mmap(o,s,i){if(g(o.node))throw n(b.ENODEV);const c=t.mmapAlloc(s);if(!c)throw n(b.ENODEV);const u=c.heap.subarray(c.ptr,c.ptr+s),w=a(o.node),y=i<w.size?Math.min(s,w.size-i):0;if(y)try{r(()=>w.file.read(u.subarray(0,y),i))}catch(W){throw c.free(),W}return u.fill(0,y),{ptr:c.ptr,allocated:!0}},msync(o,s,i,c){return d.write(o,s,0,c,i),0},fsync(o){return g(o.node)||r(()=>a(o.node).file.flush()),0}};return{mount(o){const s=f(null,"/",N);s.mount=o;for(const{path:i,file:c}of o.opts.inputs??[]){const u=i.split("/");let w=s;for(const y of u.slice(0,-1))w=w.contents[y]??f(w,y,N);f(w,u[u.length-1],Z,{file:c,size:c.getSize(),input:!0,openCount:0,unlinked:!1})}return s},node_ops:E,stream_ops:d}}function nt(e){const t=[],n=(r,a)=>{for(const[f,l]of Object.entries(r.contents)){const h=a?`${a}/${f}`:f;g(l)?n(l,h):l.wopfs&&!l.wopfs.input&&t.push({path:h,backing:l.wopfs})}};return n(e,""),t.sort((r,a)=>r.path<a.path?-1:r.path>a.path?1:0)}class M{constructor(t){O(this,"data");O(this,"size");this.data=t??new Uint8Array(0),this.size=this.data.length}read(t,n){const r=Math.max(0,Math.min(t.length,this.size-n));return t.set(this.data.subarray(n,n+r)),r}write(t,n){const r=n+t.length;return this.reserve(r),n>this.size&&this.data.fill(0,this.size,n),this.data.set(t,n),this.size=Math.max(this.size,r),t.length}truncate(t){t>this.size&&(this.reserve(t),this.data.fill(0,this.size,t)),this.size=t}getSize(){return this.size}flush(){}close(){}bytes(){return this.data.subarray(0,this.size)}reserve(t){if(t<=this.data.length)return;const n=new Uint8Array(Math.max(t,this.data.length*2,4096));n.set(this.data.subarray(0,this.size)),this.data=n}}function rt(e){let t=!1;return{read:(n,r)=>e.read(n,{at:r}),write:(n,r)=>e.write(n,{at:r}),truncate:n=>e.truncate(n),getSize:()=>e.getSize(),flush:()=>e.flush(),close:()=>{t||(t=!0,e.close())}}}const ot=1<<20;function st(e,t,n){const r=new Uint8Array(Math.min(ot,Math.max(n,1)));t.truncate(0);for(let a=0;a<n;){const f=e.read(r.subarray(0,Math.min(r.length,n-a)),a);if(f<=0)break;t.write(r.subarray(0,f),a),a+=f}}class D{constructor(t){O(this,"options");O(this,"slots");O(this,"free");O(this,"byFile",new Map);O(this,"warned",!1);this.options=t,this.slots=[...t.preopened??[]],this.free=[...this.slots].reverse();for(const n of this.slots)this.byFile.set(n.file,n)}acquire(){let t=this.free.pop();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 M)}discard(t){const n=this.byFile.get(t);if(n){try{t.truncate(0)}catch{return}this.free.push(n)}}slotOf(t){return this.byFile.get(t)}}function it(e,t,n){const r=e.FS,a=P(r,t),f=et(r,{createFile:()=>n.pool.acquire(),discardFile:m=>n.pool.discard(m),mmapAlloc:tt(e),readOnly:n.readOnly});let l;try{l=r.mount(f,{inputs:n.inputs},t)}catch(m){throw k(r,a),U(t,m)}let h="mounted";return{backend:n.kind,mountpoint:t,async commit(){if(h!=="mounted")throw new p.WopfsStateError(`commit() on a mount that is ${h}`);h="committing",I(r,l.mount);for(const{file:E}of n.inputs)E.close();const m=[];try{for(const{path:E,backing:d}of nt(l))m.push(await n.commitFile(E,d.file,d.size))}catch(E){throw new p.WopfsCommitError(m,E)}return h="committed",m},async release(){if(h!=="released"){h="releasing";try{v(r,t,l.mount,a)}finally{await n.release()}h="released"}}}}function T(e,t,n){return{kind:e,inputs:t,readOnly:!0,pool:new D({capacity:0,onExhausted:"strict",warn:()=>{}}),async commitFile(r){throw new p.WopfsStateError(`an input-only mount (no outputDir) cannot commit ${r}`)},release:n}}function _(e){return typeof e=="object"&&e!==null&&e.kind==="file"&&typeof e.getFile=="function"}function at(e){return typeof e=="object"&&e!==null&&e.kind==="directory"&&typeof e.getFileHandle=="function"}const ct={opfs:"a FileSystemFileHandle, Uint8Array or Blob",node:"a host path string, Uint8Array or Blob",memfs:"a Uint8Array, Blob or FileSystemFileHandle"};async function z(e,t,n){if(e instanceof Uint8Array)return e;if(typeof Blob<"u"&&e instanceof Blob)return new Uint8Array(await e.arrayBuffer());if(n==="memfs"&&_(e))return new Uint8Array(await(await e.getFile()).arrayBuffer());throw new p.WopfsInputError(`input ${t}: the ${n} backend takes ${ct[n]}`)}function R(){return globalThis.crypto.randomUUID().slice(0,8)}async function $(e,t){let n;try{n=await e.createSyncAccessHandle()}catch(r){const a=r==null?void 0:r.name;throw a==="NoModificationAllowedError"||a==="InvalidStateError"?new p.WopfsLockedError(t,r):r}if(typeof n.getSize()!="number")throw await n.close(),new p.WopfsUnsupportedError("this browser's FileSystemSyncAccessHandle methods are asynchronous; wopfs needs the synchronous ones");return rt(n)}async function ft(e,t,n){try{await e.move(t,n)}catch(r){if((r==null?void 0:r.name)!=="InvalidModificationError")throw r;await t.removeEntry(n),await e.move(t,n)}}async function lt(e,t,n,r,a){const f=await $(t,n);try{st(e,f,r),f.flush()}catch(l){throw f.close(),await a().catch(()=>{}),l}f.close()}async function ut(e){const t=e.outputDir;if(t!==void 0&&!at(t))throw new p.WopfsInputError("the opfs backend needs outputDir to be a FileSystemDirectoryHandle");if(t===void 0&&e.scratch>0)throw new p.WopfsInputError(`scratch (${e.scratch}) needs outputDir: without it the mount is input-only`);const n=[],r=`.wopfs-scratch-${R()}`;let a,f=0;const l=async()=>{for(const h of n)try{h.close()}catch{}a&&await t.removeEntry(r,{recursive:!0}).catch(()=>{})};try{const h=[],m=[];for(const[s,i]of e.inputs)if(_(i)){for(const[u,w]of m)if(await w.isSameEntry(i))throw new p.WopfsInputError(`inputs ${JSON.stringify(u)} and ${JSON.stringify(s)} are the same file`);m.push([s,i]);const c=await $(i,s);n.push(c),h.push({path:s,file:c})}else h.push({path:s,file:new M(await z(i,s,"opfs"))});if(t===void 0)return T("opfs",h,l);if(a=await t.getDirectoryHandle(r,{create:!0}),typeof(await a.getFileHandle("probe",{create:!0})).move!="function")throw new p.WopfsUnsupportedError("this browser's FileSystemFileHandle has no move(); wopfs needs it to commit outputs safely");const d=[];for(let s=0;s<e.scratch;s++){const i=`s${s}`,c=await a.getFileHandle(i,{create:!0}),u=await $(c,`${r}/${i}`);n.push(u),d.push({name:i,file:u,handle:c})}const o=new D({capacity:e.scratch,onExhausted:e.onExhausted,preopened:d,warn:e.warn});return{kind:"opfs",inputs:h,pool:o,async commitFile(s,i,c){const u=s.split("/"),w=u.pop();let y=t;for(const F of u)y=await y.getDirectoryHandle(F,{create:!0});const W=o.slotOf(i);let S;if(W)i.flush(),i.close(),S=W.handle;else{const F=`spill${f++}`;S=await a.getFileHandle(F,{create:!0}),await lt(i,S,`${r}/${F}`,c,()=>a.removeEntry(F)),i.close()}return await ft(S,y,w),{path:s,size:c,handle:S}},release:l}}catch(h){throw await l(),h}}async function A(e,t,n){const r=e.FS,a=[];for(const[d,o]of n.inputs)a.push([d,await z(o,d,"memfs")]);const f=P(r,t);let l;try{l=r.mount(r.filesystems.MEMFS,{},t)}catch(d){throw k(r,f),U(t,d)}const h=new Set;try{for(const[d,o]of a){const s=`${t}/${d}`;r.mkdirTree(s.slice(0,s.lastIndexOf("/"))),r.writeFile(s,o),r.chmod(s,292),h.add(r.lookupPath(s).node)}}catch(d){throw r.unmount(t),k(r,f),d}const m=(d,o,s)=>{for(const i of r.readdir(d)){if(i==="."||i==="..")continue;const c=`${d}/${i}`,u=o?`${o}/${i}`:i,w=r.lookupPath(c).node;if(r.isDir(w.mode))m(c,u,s);else if(r.isFile(w.mode)&&!h.has(w)){const y=r.readFile(c);s.push({path:u,size:y.length,bytes:y})}}};let E="mounted";return{backend:"memfs",mountpoint:t,async commit(){if(E!=="mounted")throw new p.WopfsStateError(`commit() on a mount that is ${E}`);I(r,l.mount);const d=[];return m(t,"",d),E="committed",d.sort((o,s)=>o.path<s.path?-1:o.path>s.path?1:0)},async release(){E!=="released"&&(E="releasing",v(r,t,l.mount,f),E="released")}}}function ht(e){const t=Object.entries(e.inputs??{});for(const[f]of t)q(f);const n=new Set(t.map(([f])=>f));for(const[f]of t){const l=f.split("/");for(let h=1;h<l.length;h++){const m=l.slice(0,h).join("/");if(n.has(m))throw new p.WopfsInputError(`input ${JSON.stringify(m)} is a file, but ${JSON.stringify(f)} needs it to be a directory`)}}const r=e.scratch??(e.outputDir===void 0?0:16);if(!Number.isInteger(r)||r<0)throw new p.WopfsInputError(`scratch must be a non-negative integer: ${r}`);const a=e.onExhausted??"spill";if(a!=="spill"&&a!=="strict")throw new p.WopfsInputError(`onExhausted must be "spill" or "strict": ${a}`);return{inputs:t,outputDir:e.outputDir,scratch:r,onExhausted:a,warn:e.onWarning??(f=>console.warn(f))}}async function C(e,t,n){try{return it(e,t,n)}catch(r){throw await n.release(),r}}async function pt(e,t,n={}){V(e),L(t);const r=ht(n),a=n.backend??"auto",f=a==="auto"?H():a;if(f==="memfs")return A(e,t,r);if(f==="node"){const{openNodeBackend:l}=await Promise.resolve().then(()=>require("./node-RbU1bgHg.cjs"));return C(e,t,await l(r))}if(f!=="opfs")throw new p.WopfsInputError(`unknown backend: ${String(f)}`);try{return await C(e,t,await ut(r))}catch(l){if(a==="auto"&&l instanceof p.WopfsUnsupportedError)return r.warn(`wopfs: ${l.message}; falling back to memfs`),A(e,t,r);throw l}}const dt=Object.freeze(Object.defineProperty({__proto__:null,WopfsCommitError:p.WopfsCommitError,WopfsError:p.WopfsError,WopfsInputError:p.WopfsInputError,WopfsLockedError:p.WopfsLockedError,WopfsRuntimeError:p.WopfsRuntimeError,WopfsStateError:p.WopfsStateError,WopfsUnsupportedError:p.WopfsUnsupportedError,detectBackend:H,mountFiles:pt},Symbol.toStringTag,{value:"Module"}));exports.MemoryFile=M;exports.ScratchPool=D;exports.bytesOf=z;exports.index=dt;exports.inputOnlyBackend=T;exports.randomId=R;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as E from "node:fs";
|
|
2
2
|
import * as O from "node:path";
|
|
3
|
-
import { a as f, g as I } from "./wexiftool-
|
|
4
|
-
import { r as P, M as W, b as z, i as B, S as M } from "./index-
|
|
3
|
+
import { a as f, g as I } from "./wexiftool-CRI8zlju.js";
|
|
4
|
+
import { r as P, M as W, b as z, i as B, S as M } from "./index-C7MUqxoE.js";
|
|
5
5
|
const { closeSync: N, existsSync: j, fstatSync: k, ftruncateSync: A, mkdirSync: S, openSync: g, readSync: J, realpathSync: $, renameSync: b, rmSync: q, writeFileSync: C, writeSync: G } = E, { dirname: p, isAbsolute: H, join: h, relative: K, resolve: x, sep: L } = O;
|
|
6
6
|
function v(e) {
|
|
7
7
|
let t = !1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("node:fs"),I=require("node:path"),d=require("./wexiftool-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const x=require("node:fs"),I=require("node:path"),d=require("./wexiftool-e6N3ift5.cjs"),f=require("./index-CwcAkqsP.cjs");function k(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const W=k(x),F=k(I),{closeSync:_,existsSync:q,fstatSync:E,ftruncateSync:N,mkdirSync:g,openSync:b,readSync:z,realpathSync:$,renameSync:O,rmSync:B,writeFileSync:M,writeSync:T}=W,{dirname:y,isAbsolute:A,join:p,relative:J,resolve:P,sep:C}=F;function v(e){let n=!1;return{read:(t,r)=>z(e,t,0,t.length,r),write:(t,r)=>{let o=0;for(;o<t.length;)o+=T(e,t,o,t.length-o,r+o);return o},truncate:t=>N(e,t),getSize:()=>E(e).size,flush:()=>{},close:()=>{n||(n=!0,_(e))}}}function D(e,n,t,r=!1){const o=J(P(e),n);if(!o&&!r||o===".."||o.startsWith(`..${C}`)||A(o))throw new d.WopfsError(`refusing to commit ${JSON.stringify(t)}: it resolves outside outputDir`)}async function G(e){const n=e.outputDir;if(n!==void 0&&typeof n!="string")throw new d.WopfsInputError("the node backend needs outputDir to be a host directory path");if(n===void 0&&e.scratch>0)throw new d.WopfsInputError(`scratch (${e.scratch}) needs outputDir: without it the mount is input-only`);const t=[],r=n===void 0?"":p(n,`.wopfs-scratch-${f.randomId()}`);let o=!1,j=0;const h=async()=>{for(const u of t)try{u.close()}catch{}o&&B(r,{recursive:!0,force:!0})};try{const u=[];for(const[s,c]of e.inputs)if(typeof c=="string"){let a;try{a=b(c,"r")}catch(l){throw new d.WopfsInputError(`input ${s}: cannot open ${c}: ${l.message}`,{cause:l})}const i=v(a);if(t.push(i),!E(a).isFile())throw new d.WopfsInputError(`input ${s}: ${c} is not a regular file`);u.push({path:s,file:i})}else u.push({path:s,file:new f.MemoryFile(await f.bytesOf(c,s,"node"))});if(n===void 0)return f.inputOnlyBackend("node",u,h);g(r,{recursive:!0}),o=!0;const w=new f.ScratchPool({capacity:e.scratch,onExhausted:e.onExhausted,warn:e.warn,open:s=>{const c=`s${s}`,a=v(b(p(r,c),"w+"));return t.push(a),{name:c,file:a}}});return{kind:"node",inputs:u,pool:w,async commitFile(s,c,a){const i=P(n,...s.split("/"));D(n,i,s);let l=y(i);for(;!q(l);)l=y(l);D($(n),$(l),s,!0),g(y(i),{recursive:!0});const S=w.slotOf(c);if(S)c.close(),O(p(r,S.name),i);else{const m=p(r,`spill${j++}`);M(m,c.bytes()),O(m,i)}return{path:s,size:a,hostPath:i}},release:h}}catch(u){throw await h(),u}}exports.openNodeBackend=G;
|