@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
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var X=Object.create;var S=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,tt=Object.prototype.hasOwnProperty;var et=(r,t,e)=>t in r?S(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var rt=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Y(t))!tt.call(r,o)&&o!==e&&S(r,o,{get:()=>t[o],enumerable:!(n=Q(t,o))||n.enumerable});return r};var g=(r,t,e)=>(e=r!=null?X(Z(r)):{},rt(t||!r||!r.__esModule?S(e,"default",{value:r,enumerable:!0}):e,r));var P=(r,t,e)=>et(r,typeof t!="symbol"?t+"":t,e);var F=typeof document<"u"?document.currentScript:null;class v extends Error{constructor(t,e){super(t,e),this.name=new.target.name}}class nt extends v{}class ot extends v{constructor(e,n){super(`${e} is locked by another sync access handle (another tab or worker may be using it)`,{cause:n});P(this,"path");this.path=e}}class B extends v{}class it extends v{}class st extends v{}class at extends v{constructor(e,n){super(`commit() failed after ${e.length} file(s): ${(n==null?void 0:n.message)??String(n)}`,{cause:n});P(this,"committed");this.committed=e}}function ct(r,t,e,n=","){const o=M(t),s=r==="json"?lt(o,e):ut(o,e,n);return s===o?t:H(s)}function lt(r,t){return r.replace(/("SourceFile"\s*:\s*)("(?:[^"\\]|\\.)*")/g,(e,n,o)=>{let s;try{s=JSON.parse(N(o))}catch{return e}const i=t(s);return i===void 0?e:n+M(new TextEncoder().encode(JSON.stringify(i)))})}function ut(r,t,e){var c;const n=ft(r,e);if(n.length===0)return r;const o=n[0].map(l=>j(r.slice(l.start,l.end)).replace(/^\xef\xbb\xbf/,""));let s=o.indexOf("SourceFile");if(s<0&&((c=o[0])==null?void 0:c.toLowerCase())==="sourcefile"&&(s=0),s<0)return r;let i="",a=0;for(const l of n.slice(1)){const u=l[s];if(!u)continue;const h=t(N(j(r.slice(u.start,u.end))));h!==void 0&&(i+=r.slice(a,u.start)+'"'+M(new TextEncoder().encode(h)).replaceAll('"','""')+'"',a=u.end)}return i+r.slice(a)}function ft(r,t){const e=[];let n=[],o=0;for(;o<r.length;){const s=o;let i=o;for(;r[i]===" ";)i++;if(r[i]==='"'){for(i++;i<r.length;)if(r[i]==='"')if(r[i+1]==='"')i+=2;else break;else i++;for(i++;i<r.length&&!r.startsWith(t,i)&&r[i]!==`
|
|
2
|
+
`&&r[i]!=="\r";)i++}else for(;i<r.length&&!r.startsWith(t,i)&&r[i]!==`
|
|
3
|
+
`&&r[i]!=="\r";)i++;if(n.push({start:s,end:i}),r.startsWith(t,i)){o=i+t.length;continue}e.push(n),n=[],r[i]==="\r"&&r[i+1]===`
|
|
4
|
+
`?o=i+2:o=i+1}return n.length>0&&e.push(n),e}function j(r){const t=r.replace(/^ +/,"");return t.startsWith('"')?t.slice(1).replace(/"\s*$/,"").replaceAll('""','"'):t.replace(/[ \n\r]+$/,"")}function M(r){let t="";for(let e=0;e<r.length;e+=32768)t+=String.fromCharCode(...r.subarray(e,e+32768));return t}function H(r){const t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}function N(r){return new TextDecoder().decode(H(r))}const b="/wexiftool",dt="/opt/perlwasm/bin/exiftool";function ht(r){r.ENV&&(r.ENV.LC_ALL="C")}class wt{constructor(t,e){this.wasmUrl=t,this.onWasmProgress=e,this.module=null,this.modulePromise=null,this.tail=Promise.resolve(),this.createModule=null,this.stdoutSink=null,this.stderrSink=null}async init(){if(!this.module){if(this.modulePromise){await this.modulePromise;return}this.modulePromise=this.loadModule(),this.module=await this.modulePromise;try{this.module.FS.mkdir(b)}catch{}}}async loadModule(){const t={noInitialRun:!0,print:s=>{var i;(i=this.stdoutSink)==null||i.call(this,s)},printErr:s=>{var i;(i=this.stderrSink)==null||i.call(this,s)},preRun:[ht]},e=this.wasmUrl??this.defaultWasmUrl(),n=await this.importModuleFactory(e);this.createModule=n;const o=e.substring(0,e.lastIndexOf("/")+1);if(this.onWasmProgress&&typeof fetch<"u"&&!T()){const s=await this.fetchWithProgress(o+"perl.wasm");return await n({...t,locateFile:i=>o+i,wasmBinary:s})}return await n({...t,locateFile:s=>o+s})}async fetchWithProgress(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch ${t}: ${e.status} ${e.statusText}`);const n=e.headers.get("content-length"),o=n?parseInt(n,10):null,s=e.body.getReader(),i=[];let a=0;for(;;){const{done:u,value:h}=await s.read();if(u)break;i.push(h),a+=h.byteLength,this.onWasmProgress(a,o)}const c=new Uint8Array(a);let l=0;for(const u of i)c.set(u,l),l+=u.byteLength;return c}async importModuleFactory(t){if(T()){const s=await import(t);return s.default??s}const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch ${t}: ${e.status} ${e.statusText}`);const n=await e.text();return new Function("exports","module","define",`${n}
|
|
5
|
+
return createPerlModule;`)(void 0,void 0,void 0)}defaultWasmUrl(){return new URL("../wasm/perl.js",typeof document>"u"?require("url").pathToFileURL(__filename).href:F&&F.tagName.toUpperCase()==="SCRIPT"&&F.src||new URL("wexiftool-e6N3ift5.cjs",document.baseURI).href).href}async exec(t,e){const n=[...e].map(([i,a])=>({name:i,source:a})),{committed:o,...s}=await this.run(t,n);return s}async run(t,e,n={}){return await this.init(),e=await mt(t,e),this.enqueue(()=>{var o;return e.some(s=>!(s.source instanceof Uint8Array))||(o=n.outputs)!=null&&o.length?this.runMounted(t,e,n):this.runStaged(t,e)})}runStaged(t,e){const n=this.module.FS,o=e.map((i,a)=>`${b}/${a}/${W(i)}`),s=new Map;try{e.forEach((a,c)=>{n.mkdir(`${b}/${c}`),n.writeFile(o[c],a.source),n.chmod(o[c],292),s.set(o[c],_(n,o[c]))});const i=this.callExiftool(t,e,o,new Map);return e.forEach((a,c)=>{if(_(n,o[c])!==s.get(o[c]))try{i.files.set(a.name,n.readFile(o[c]))}catch{}}),{...i,committed:new Map}}finally{e.forEach((i,a)=>q(n,`${b}/${a}`))}}async runMounted(t,e,n){var c;if(T()&&!globalThis.crypto){const{webcrypto:l}=await import("node:crypto");Object.defineProperty(globalThis,"crypto",{value:l,configurable:!0,writable:!0})}const{mountFiles:o}=await Promise.resolve().then(()=>require("./index-CwcAkqsP.cjs")).then(l=>l.index),s=this.module,i=e.map((l,u)=>`${b}/${u}/${W(l)}`),a=[];try{for(const[m,d]of e.entries()){const y=((c=d.commitTo)==null?void 0:c.dir)??(n.readOnly?void 0:n.privateDir);if(y===void 0&&!n.readOnly)throw new Error(`Input "${d.name}" is mounted, so the run needs a privateDir, a commitTo or readOnly`);a.push(await o(s,`${b}/${m}`,{inputs:{[W(d)]:d.source},outputDir:y,scratch:y===void 0?0:n.scratch??1,onExhausted:"spill",backend:n.backend}))}const l=n.outputs??[],u=new Map;for(const[m,d]of l.entries()){const y=`${b}/o${m}`;a.push(await o(s,y,{inputs:Object.fromEntries(d.existing.map(w=>[w,`${d.dir}/${w}`])),outputDir:d.dir,scratch:n.scratch??(d.file===void 0?Math.max(1,e.length):1),onExhausted:"spill",backend:n.backend})),u.set(d.name,d.file===void 0?`${y}/`:`${y}/${d.file}`)}const h=this.callExiftool(t,e,i,u),f=new Map;for(const[m,d]of e.entries()){const y=await a[m].commit(),w=y.find(p=>p.path===W(d));if(d.commitTo)w&&f.set(d.name,w);else for(const p of y)p===w&&h.files.set(d.name,await Et(p)),await vt(p,n.privateDir)}for(const[m,d]of l.entries())for(const y of await a[e.length+m].commit())f.set(d.file===void 0?bt(d.name,y.path):d.name,y);return{...h,committed:f}}finally{for(const l of a)await l.release()}}callExiftool(t,e,n,o){const s=this.module,i=new Map(e.map((f,m)=>[f.name,n[m]])),a=[dt],c=new Set;for(const f of t){if(f.toLowerCase()==="-overwrite_original_in_place"){a.push("-overwrite_original");continue}const m=i.get(f)??o.get(f);if(m!==void 0){c.add(f),a.push(m);continue}const d=gt.exec(f),y=d?i.get(d[2]):void 0;if(d&&y!==void 0){c.add(d[2]),a.push(d[1]+y);continue}a.push(f)}for(const f of e)c.has(f.name)||a.push(i.get(f.name));let l="",u="";this.stdoutSink=f=>{l+=f+`
|
|
6
|
+
`},this.stderrSink=f=>{u+=f+`
|
|
7
|
+
`};let h;try{h=s.callMain(a)}catch(f){if(f.status!==void 0)h=f.status;else throw f}finally{this.stdoutSink=null,this.stderrSink=null}for(const[f,m]of[...i,...o])l=l.replaceAll(m,f),u=u.replaceAll(m,f);return e.forEach((f,m)=>{const d=new RegExp(`${b}/${m}(?![0-9])`,"g"),y=f.name.lastIndexOf("/"),w=y>0?f.name.slice(0,y):y===0?"/":".";l=l.replace(d,()=>w),u=u.replace(d,()=>w)}),{stdout:l.trimEnd(),stderr:u.trimEnd(),exitCode:h,files:new Map}}enqueue(t){const e=this.tail.then(t,t);return this.tail=e.catch(()=>{}),e}destroy(){this.module=null,this.modulePromise=null,this.createModule=null,this.tail=Promise.resolve()}}async function mt(r,t){var a;const e=r.findIndex(c=>c.toLowerCase()==="-csvdelim"),n=e>=0?(a=r[e+1])==null?void 0:a.replaceAll("\\t"," "):void 0,o=(c,l)=>`${b}/${l}/${W(c)}`,s=c=>{const l=c.toLowerCase(),u=t.findIndex(h=>h.name===c||h.name.toLowerCase()===l||typeof h.source=="string"&&(h.source===c||h.source.toLowerCase()===l));return u<0?void 0:o(t[u],u)},i=[...t];for(const c of r){const l=pt.exec(c),u=l?t.findIndex(m=>m.name===l[2]):-1;if(!l||u<0)continue;const h=l[1].toLowerCase()==="csv"?"csv":"json",f=ct(h,await yt(t[u].source),s,n);i[u]={name:t[u].name,source:f}}return i}async function yt(r){if(r instanceof Uint8Array)return r;if(typeof r=="string"){const{readFile:t}=await import("node:fs/promises");return new Uint8Array(await t(r))}return new Uint8Array(await(await r.getFile()).arrayBuffer())}const pt=/^-(csv|j|json)\+?=(.+)$/i,gt=/^(-(?:csv|j|json)\+?=|-geotag=)(.+)$/i;function bt(r,t){return r.endsWith("/")?r+t:`${r}/${t}`}function T(){var r;return typeof process<"u"&&!!((r=process.versions)!=null&&r.node)}function W(r){var e;const t=(((e=r.commitTo)==null?void 0:e.as)??r.name).split("/").pop();return t&&t!=="."&&t!==".."?t:"input.bin"}function _(r,t){try{const e=r.stat(t);return`${e.ino}:${e.size}:${+e.mtime}`}catch{return"missing"}}function q(r,t){let e;try{e=r.readdir(t)}catch{return}for(const n of e){if(n==="."||n==="..")continue;const o=`${t}/${n}`;try{r.unlink(o)}catch{q(r,o)}}try{r.rmdir(t)}catch{}}async function Et(r){if(r.handle)return new Uint8Array(await(await r.handle.getFile()).arrayBuffer());if(r.hostPath){const{readFile:t}=await import("node:fs/promises");return new Uint8Array(await t(r.hostPath))}return r.bytes??new Uint8Array}async function vt(r,t){if(r.hostPath){const{rm:e}=await import("node:fs/promises");await e(r.hostPath,{force:!0});return}if(typeof t!="string"){const e=r.path.split("/"),n=e.pop();let o=t;for(const s of e)o=await o.getDirectoryHandle(s);await o.removeEntry(n).catch(()=>{})}}function E(r){return typeof r=="object"&&r!==null&&r.kind==="file"&&typeof r.getFile=="function"}async function x(r){if(r instanceof Uint8Array)return{name:"input.bin",data:r};if(r instanceof ArrayBuffer)return{name:"input.bin",data:new Uint8Array(r)};if(E(r)){const t=await r.getFile();return{name:r.name||"input.bin",data:new Uint8Array(await t.arrayBuffer())}}if(typeof File<"u"&&r instanceof File){const t=await r.arrayBuffer();return{name:r.name||"input.bin",data:new Uint8Array(t)}}if(typeof Blob<"u"&&r instanceof Blob){const t=await r.arrayBuffer();return{name:"input.bin",data:new Uint8Array(t)}}throw new Error("Unsupported input type")}async function $t(r,t){const e=Wt(t);if(typeof r.createSyncAccessHandle=="function"){let n;try{n=await r.createSyncAccessHandle()}catch(o){if(typeof r.createWritable!="function")throw o;return R(r,e)}try{n.truncate(0);let o=0;for(;o<e.byteLength;){const s=o===0?e:e.slice(o),i=n.write(s,{at:o});if(i<=0)throw new Error(`Short write to ${r.name} at byte ${o} of ${e.byteLength}`);o+=i}n.flush()}finally{n.close()}return}if(typeof r.createWritable=="function")return R(r,e);throw new Error(`Cannot write to file handle "${r.name}": it has neither createSyncAccessHandle() (dedicated workers only) nor createWritable().`)}async function R(r,t){const e=await r.createWritable();try{await e.write(t),await e.close()}catch(n){throw await e.abort(n).catch(()=>{}),n}}function Wt(r){const{buffer:t,byteOffset:e,byteLength:n}=r;return t instanceof ArrayBuffer&&e===0&&n===t.byteLength?t:r.slice().buffer}const kt=Object.freeze(Object.defineProperty({__proto__:null,isFileHandle:E,resolveInput:x,writeToHandle:$t},Symbol.toStringTag,{value:"Module"})),J=".wexiftool";function C(){var s,i;const r=globalThis,t=!!((i=(s=r.process)==null?void 0:s.versions)!=null&&i.node)&&typeof r.window>"u",e=r.DedicatedWorkerGlobalScope,n=r.FileSystemFileHandle,o=!t&&typeof e=="function"&&globalThis instanceof e&&!!(n&&"createSyncAccessHandle"in n.prototype);return{node:t,opfs:o}}async function O(r,t,e,n){if(typeof t=="string"){if(!e.node)throw new Error(`"${t}": file paths are only supported under Node`);const{resolve:s,dirname:i,basename:a}=await import("node:path"),c=s(t);if(n===void 0)return{input:{name:r,source:c}};if(typeof n!="string")return{input:{name:r,source:c},writeAfter:n};const l=s(n);return a(l)!==a(c)?{input:{name:r,source:c},writeAfter:l}:{input:{name:r,source:c,commitTo:{dir:i(l),as:a(l)}}}}if(E(t)&&e.opfs&&await z(t)){const s=t;if(n===void 0)return{input:{name:r,source:s}};const i=E(n)&&n.name===t.name?await Ft(n):null;return i?{input:{name:r,source:s,commitTo:{dir:i,as:n.name}}}:{input:{name:r,source:s},writeAfter:n}}const{data:o}=await x(t);return{input:{name:r,source:o},writeAfter:n}}const U=new WeakMap;async function At(r,t){try{const e=await St(t);e&&await e.isSameEntry(r)&&U.set(r,t)}catch{}}async function xt(r){return(await navigator.storage.getDirectory()).resolve(r)}async function St(r){if(r.length===0)return null;let t=await navigator.storage.getDirectory();for(const e of r.slice(0,-1))t=await t.getDirectoryHandle(e);return t.getFileHandle(r[r.length-1])}const Pt=5e3;async function z(r){const t=U.get(r);if(t)return t;const n=[[await navigator.storage.getDirectory(),[]]];let o=0;for(;n.length>0;){const[s,i]=n.shift();for await(const[a,c]of s.entries()){if(++o>Pt)return null;if(c.kind==="file"){if(a===r.name&&await c.isSameEntry(r)){const l=[...i,a];return U.set(r,l),l}}else i.length===0&&a===J||n.push([c,[...i,a]])}}return null}async function Ft(r){const t=await z(r);if(!t)return null;let e=await navigator.storage.getDirectory();for(const n of t.slice(0,-1))e=await e.getDirectoryHandle(n);return e}async function G(r,t){if(r.node){const{mkdtemp:i,rm:a}=await import("node:fs/promises"),{tmpdir:c}=await import("node:os"),{join:l}=await import("node:path"),u=await i(l(c(),"wexiftool-"));try{return await t(u)}finally{await a(u,{recursive:!0,force:!0})}}const e=globalThis.crypto.randomUUID().slice(0,8),o=await(await navigator.storage.getDirectory()).getDirectoryHandle(J,{create:!0}),s=await o.getDirectoryHandle(e,{create:!0});try{return await t(s)}finally{await o.removeEntry(e,{recursive:!0}).catch(()=>{})}}async function I(r,t){if(typeof r=="string"){const{writeFile:n}=await import("node:fs/promises");await n(r,t);return}const{writeToHandle:e}=await Promise.resolve().then(()=>kt);await e(r,t)}const V=Object.freeze(Object.defineProperty({__proto__:null,detectEnvironment:C,planInput:O,registerHint:At,resolveOnCallerSide:xt,withPrivateDir:G,writeRef:I},Symbol.toStringTag,{value:"Module"}));function K(r){const t=r,e=[];return"input"in t&&e.push(t.input),t.inputs&&e.push(...t.inputs),t.files&&e.push(...t.files.values()),t.options&&"output"in t.options&&e.push(t.options.output),e.filter(E)}class L{constructor(t,e){this.port=t,this.onWasmProgress=e,this.nextId=1,this.pending=new Map,this.destroyed=!1,t.addEventListener("message",n=>this.receive(n.data)),t.addEventListener("error",n=>this.failAll(Ot(n,"Worker error"))),t.addEventListener("messageerror",()=>this.failAll("Worker sent a message that could not be deserialized"))}static async create(t,e){const n=new L(t,e==null?void 0:e.onWasmProgress);return await n.call({op:"init",options:{wasmUrl:e==null?void 0:e.wasmUrl,progress:!!(e!=null&&e.onWasmProgress)}}),n}read(t){return this.call({op:"read",input:t})}readMany(t){return this.call({op:"readMany",inputs:t})}readRaw(t,e){return this.call({op:"readRaw",input:t,args:e})}write(t,e,n){return this.call({op:"write",input:t,tags:e,options:n})}exec(t,e,n){return this.call({op:"exec",args:t,files:e,options:n})}async destroy(){if(this.destroyed=!0,typeof this.port.terminate=="function"){this.port.terminate(),this.failAll("WExifToolWorker was destroyed");return}await this.call({op:"destroy"})}async call(t){const e=this.nextId++,n=await Tt(t);if(this.destroyed&&t.op!=="destroy")throw new Error("WExifToolWorker was destroyed");return new Promise((o,s)=>{this.pending.set(e,{resolve:o,reject:s});try{this.port.postMessage({...t,id:e,hints:n})}catch(i){this.pending.delete(e),s(i instanceof Error?i:new Error(String(i)))}})}receive(t){var n;if(t.kind==="progress"){(n=this.onWasmProgress)==null||n.call(this,t.loaded,t.total);return}const e=this.pending.get(t.id);e&&(this.pending.delete(t.id),t.ok?e.resolve(t.value):e.reject(new Error(t.error)))}failAll(t){const e=new Error(t);for(const n of this.pending.values())n.reject(e);this.pending.clear()}}async function Tt(r){var o,s;const t=globalThis;if(typeof t.window>"u"||typeof((s=(o=t.navigator)==null?void 0:o.storage)==null?void 0:s.getDirectory)!="function")return;const e=K(r);if(e.length===0)return;const{resolveOnCallerSide:n}=await Promise.resolve().then(()=>V);return Promise.all(e.map(i=>n(i).catch(()=>null)))}function Ot(r,t){const e=r==null?void 0:r.message;return typeof e=="string"&&e?`${t}: ${e}`:t}class D{constructor(t){this.glue=t}static async create(t){const e=new wt(t==null?void 0:t.wasmUrl,t==null?void 0:t.onWasmProgress);return await e.init(),new D(e)}async read(t){const e=A(t),n=await this.runFiles(["-json","-G",e],[[e,t]],{readOnly:!0});if(n.exitCode!==0&&n.stderr)throw new Error(`ExifTool error: ${n.stderr}`);try{const o=JSON.parse(n.stdout);return Array.isArray(o)?o[0]:o}catch{throw new Error(`Failed to parse ExifTool output: ${n.stdout}`)}}async readMany(t){if(t.length===0)return[];const e=Ut(t.map(A)),n=await this.runFiles(["-json","-G",...e],t.map((s,i)=>[e[i],s]),{readOnly:!0});let o;try{o=JSON.parse(n.stdout)}catch{throw new Error(`ExifTool error: ${n.stderr||`unparseable output: ${n.stdout}`}`)}if(!Array.isArray(o)||o.length!==t.length)throw new Error(`ExifTool error: ${n.stderr||`expected ${t.length} results`}`);return o}async write(t,e,n){const o=A(t),s=Object.entries(e).map(([l,u])=>`-${l}=${u}`),i=typeof t=="string"||E(t),a=i?(n==null?void 0:n.output)??t:void 0,c=await this.runFiles(["-overwrite_original",...s,o],[[o,t]],{targets:a===void 0?void 0:new Map([[o,a]])});if(c.exitCode!==0&&c.stderr)throw new Error(`ExifTool error: ${c.stderr}`);return i?(!c.written.includes(o)&&a!==t&&await I(a,(await x(t)).data),a):c.files.get(o)??(await x(t)).data}async readRaw(t,e){const n=A(t),o=await this.runFiles([...e,n],[[n,t]],{scratch:0});if(o.exitCode!==0&&o.stderr)throw new Error(`ExifTool error: ${o.stderr}`);return o.stdout}async exec(t,e,n){var c;const o=[...e??[]],s=n==null?void 0:n.writeBack,i=s?new Map(o.filter(([l,u])=>(typeof u=="string"||E(u))&&(s===!0||s.includes(l)))):void 0,a=(c=n==null?void 0:n.outputs)!=null&&c.length?await Mt(n.outputs,o):void 0;return this.runFiles(t,o,{targets:i,outputs:a})}async runFiles(t,e,n){const o=C();try{return await this.runPlanned(t,e,n,o)}catch(s){if(o.opfs&&s instanceof B)return this.runPlanned(t,e,n,{...o,opfs:!1});throw s}}async runPlanned(t,e,{targets:n,scratch:o,readOnly:s,outputs:i},a){var y;const c=[],l=[];for(const[w,p]of e){let $=await O(w,p,a,n==null?void 0:n.get(w));const k=$.input.source;typeof k=="object"&&!(k instanceof Uint8Array)&&(await It(k,l)?$=await O(w,p,{...a,opfs:!1},n==null?void 0:n.get(w)):l.push(k)),c.push($)}const u=c.map(w=>w.input);let h;if(!i&&u.every(w=>w.source instanceof Uint8Array))h=await this.glue.exec(t,new Map(u.map(w=>[w.name,w.source])));else{const w=a.node?"node":"opfs";h=!s&&u.some(p=>!p.commitTo)?await G(a,p=>this.glue.run(t,u,{privateDir:p,backend:w,scratch:o,outputs:i})):await this.glue.run(t,u,{backend:w,scratch:o,readOnly:s,outputs:i})}const f=[...((y=h.committed)==null?void 0:y.keys())??[]];for(const{input:w,writeAfter:p}of c){const $=h.files.get(w.name);p&&$&&(await I(p,$),h.files.delete(w.name),f.push(w.name))}const{committed:m,...d}=h;return{...d,written:f}}destroy(){this.glue.destroy()}}function A(r){return typeof r=="string"?r:(E(r)||typeof File<"u"&&r instanceof File)&&r.name||"input.bin"}function Ut(r){const t=new Set(r),e=new Map;return r.map(n=>{const o=(e.get(n)??0)+1;if(e.set(n,o),o===1)return n;const s=n.lastIndexOf("/"),i=n.lastIndexOf("."),a=i>s+1?i:n.length;let c=o,l=`${n.slice(0,a)} (${c})${n.slice(a)}`;for(;t.has(l);)l=`${n.slice(0,a)} (${++c})${n.slice(a)}`;return t.add(l),l})}async function It(r,t){for(const e of t)if(e===r||await e.isSameEntry(r))return!0;return!1}async function Mt(r,t){var u;if(!C().node)throw new Error("exec() outputs are only supported under Node");const{mkdir:e,stat:n}=await import("node:fs/promises"),{resolve:o,dirname:s,basename:i,join:a}=await import("node:path"),c=h=>n(h).then(f=>f,()=>null),l=[];for(const h of r){const f=o(h),m=await c(f);if(h.endsWith("/")||m!=null&&m.isDirectory()){const d=[];for(const[y]of t){const w=i(y);(u=await c(a(f,w)))!=null&&u.isFile()&&d.push(w)}await e(f,{recursive:!0}),l.push({name:h,dir:f,existing:d})}else await e(s(f),{recursive:!0}),l.push({name:h,dir:s(f),file:i(f),existing:m?[i(f)]:[]})}return l}exports.WExifTool=D;exports.WExifToolWorker=L;exports.WopfsCommitError=at;exports.WopfsError=v;exports.WopfsInputError=nt;exports.WopfsLockedError=ot;exports.WopfsRuntimeError=it;exports.WopfsStateError=st;exports.WopfsUnsupportedError=B;exports.handlesIn=K;exports.isFileHandle=E;exports.mounts=V;
|
package/dist/wexiftool.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./wexiftool-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./wexiftool-e6N3ift5.cjs");exports.WExifTool=o.WExifTool;exports.WExifToolWorker=o.WExifToolWorker;
|
package/dist/wexiftool.d.ts
CHANGED
|
@@ -7,8 +7,20 @@ export declare interface ExecOptions {
|
|
|
7
7
|
/**
|
|
8
8
|
* Write changed files back to the handles and host paths they came from,
|
|
9
9
|
* instead of returning their bytes. Byte inputs are always returned.
|
|
10
|
+
* `true` covers every handle and path input. A list covers only the
|
|
11
|
+
* inputs with those names, so the others, such as a `-tagsFromFile`
|
|
12
|
+
* source, are only read.
|
|
10
13
|
*/
|
|
11
|
-
writeBack?: boolean;
|
|
14
|
+
writeBack?: boolean | readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Node only. Host paths that `args` name for ExifTool to create, such as
|
|
17
|
+
* `OUT` in `-o OUT`, written in `args` exactly as here. A path ending in
|
|
18
|
+
* `/`, or an existing directory, is a directory to create files in, as
|
|
19
|
+
* with `-o DIR/`. Whatever the run creates there is written to that place
|
|
20
|
+
* on disk and listed in `result.written`. Files already there are visible
|
|
21
|
+
* to ExifTool, so `-o` refuses to replace one, as native ExifTool does.
|
|
22
|
+
*/
|
|
23
|
+
outputs?: readonly string[];
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
/**
|
|
@@ -20,7 +32,11 @@ export declare interface ExecResult {
|
|
|
20
32
|
exitCode: number;
|
|
21
33
|
/** Files the run changed, as bytes, keyed by name. */
|
|
22
34
|
files: Map<string, Uint8Array>;
|
|
23
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* With `writeBack`, the names of the files written back in place. With
|
|
37
|
+
* `outputs`, also each file created there: an output file's name, or a
|
|
38
|
+
* directory output's name followed by the file's name.
|
|
39
|
+
*/
|
|
24
40
|
written?: string[];
|
|
25
41
|
}
|
|
26
42
|
|
package/dist/wexiftool.es.js
CHANGED
package/dist/worker.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const c=require("./wexiftool-
|
|
1
|
+
"use strict";const c=require("./wexiftool-e6N3ift5.cjs");function p(l,r=c.WExifTool.create){let i=null;const f=(a,n=[])=>l.postMessage(a,n),o=()=>(i||(i=r()),i);l.addEventListener("message",a=>{const n=a.data,e=t=>f({kind:"result",id:n.id,ok:!1,error:t instanceof Error?t.message:String(t)});d(n).then(({value:t,transfer:s})=>{try{f({kind:"result",id:n.id,ok:!0,value:t},s)}catch(w){e(w)}},e)});async function d(a){if(a.hints){const{registerHint:n}=await Promise.resolve().then(()=>require("./wexiftool-e6N3ift5.cjs")).then(t=>t.mounts),e=c.handlesIn(a);for(const[t,s]of a.hints.entries())s&&e[t]&&await n(e[t],s)}switch(a.op){case"init":{const{wasmUrl:n,progress:e}=a.options;return i=r({wasmUrl:n,onWasmProgress:e?(t,s)=>f({kind:"progress",loaded:t,total:s}):void 0}),await i,{value:null}}case"read":return{value:await(await o()).read(a.input)};case"readMany":return{value:await(await o()).readMany(a.inputs)};case"readRaw":return{value:await(await o()).readRaw(a.input,a.args)};case"write":{const n=await o();if(c.isFileHandle(a.input))return{value:await n.write(a.input,a.tags,a.options)};if(typeof a.input=="string")return{value:await n.write(a.input,a.tags)};const e=await n.write(a.input,a.tags);return{value:e,transfer:u([e])}}case"exec":{const n=await(await o()).exec(a.args,a.files,a.options);return{value:n,transfer:u(n.files.values())}}case"destroy":return i&&(await i).destroy(),i=null,{value:null}}}}function u(l){const r=new Set;for(const i of l)i.buffer instanceof ArrayBuffer&&r.add(i.buffer);return[...r]}p(self);
|
package/dist/worker.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { W as u, h as p, i as v } from "./wexiftool-
|
|
1
|
+
import { W as u, h as p, i as v } from "./wexiftool-CRI8zlju.js";
|
|
2
2
|
function g(l, r = u.create) {
|
|
3
3
|
let i = null;
|
|
4
4
|
const f = (a, n = []) => l.postMessage(a, n), o = () => (i || (i = r()), i);
|
|
@@ -19,7 +19,7 @@ function g(l, r = u.create) {
|
|
|
19
19
|
});
|
|
20
20
|
async function d(a) {
|
|
21
21
|
if (a.hints) {
|
|
22
|
-
const { registerHint: n } = await import("./wexiftool-
|
|
22
|
+
const { registerHint: n } = await import("./wexiftool-CRI8zlju.js").then((t) => t.m), s = p(a);
|
|
23
23
|
for (const [t, e] of a.hints.entries())
|
|
24
24
|
e && s[t] && await n(s[t], e);
|
|
25
25
|
}
|
package/package.json
CHANGED
package/wasm/perl.wasm
CHANGED