"use strict";var h=Object.create;var r=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var u=(t,e)=>r(t,"name",{value:e,configurable:!0});var N=(t,e)=>{for(var i in e)r(t,i,{get:e[i],enumerable:!0})},m=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of D(e))!b.call(t,a)&&a!==i&&r(t,a,{get:()=>e[a],enumerable:!(n=w(e,a))||n.enumerable});return t};var g=(t,e,i)=>(i=t!=null?h(I(t)):{},m(e||!t||!t.__esModule?r(i,"default",{value:t,enumerable:!0}):i,t)),_=t=>m(r({},"__esModule",{value:!0}),t);var B={};N(B,{default:()=>o});module.exports=_(B);var c=require("@taichunmin/buffer"),p=g(require("jszip")),s=g(require("lodash"));var o=class{static{u(this,"DfuZip")}#i;#e=null;#t=null;constructor(e){this.#i=e}async getManifest(){if(s.default.isNil(this.#e)&&(this.#e=await p.default.loadAsync(this.#i)),s.default.isNil(this.#t)){let e=await this.#e.file("manifest.json")?.async("string");if(s.default.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 i=await this.getManifest();for(let n of e){let a=i[n];if(s.default.isNil(a))continue;let[d,y]=await Promise.all(s.default.map([a.dat_file,a.bin_file],async f=>{let l=await this.#e?.file(f)?.async("uint8array");if(s.default.isNil(l))throw new Error(`Failed to read ${f} from DFU package`);return c.Buffer.fromView(l)}));return{type:n,header:d,body:y}}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 s.default.isNil(e)?null:e.body.toString("utf8").match(/\x00(v\d+(?:\.\d+)*[\w-]*)\x00/)?.[1]??null}};((globalThis??{}).ChameleonUltraJS??{}).DfuZip=o;
//# sourceMappingURL=DfuZip.js.map