var g=Object.defineProperty;var f=(s,e)=>g(s,"name",{value:e,configurable:!0});import{Buffer as c}from"@taichunmin/buffer";import p from"jszip";import t from"lodash";var i=class{static{f(this,"DfuZip")}#i;#e=null;#t=null;constructor(e){this.#i=e}async getManifest(){if(t.isNil(this.#e)&&(this.#e=await p.loadAsync(this.#i)),t.isNil(this.#t)){let e=await this.#e.file("manifest.json")?.async("string");if(t.isNil(e))throw new Error("Unable to find manifest, is this a proper DFU package?");this.#t=JSON.parse(e).manifest}return this.#t}async getImage(e){let l=await this.getManifest();for(let n of e){let a=l[n];if(t.isNil(a))continue;let[u,m]=await Promise.all(t.map([a.dat_file,a.bin_file],async r=>{let o=await this.#e?.file(r)?.async("uint8array");if(t.isNil(o))throw new Error(`Failed to read ${r} from DFU package`);return c.fromView(o)}));return{type:n,header:u,body:m}}return null}async getBaseImage(){return await this.getImage(["softdevice","bootloader","softdevice_bootloader"])}async getAppImage(){return await this.getImage(["application"])}async getGitVersion(){let e=await this.getAppImage();return t.isNil(e)?null:e.body.toString("utf8").match(/\x00(v\d+(?:\.\d+)*[\w-]*)\x00/)?.[1]??null}};((globalThis??{}).ChameleonUltraJS??{}).DfuZip=i;export{i as default};
//# sourceMappingURL=DfuZip.mjs.map