"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getFileInfoLength=getFileInfoLength,exports.getFileContentLength=getFileContentLength,exports.getFileCount=getFileCount,exports.getFileInfo=getFileInfo,exports.default=unpack;const fs=require("fs"),path=require("path"),mkdir=require("mkdir-p"),INFO_LENGTH_BEGIN=5,INFO_LENGTH_END=9,FILE_LENGTH_BEGIN=9,FILE_LENGTH_END=13,FILE_COUNT_BEGIN=14,FILE_COUNT_END=18,FILF_INFO_BEGIN=18;function getFileInfoLength(e){return e.slice(5,9).readInt32BE(0)}function getFileContentLength(e){return e.slice(9,13).readInt32BE(0)}function getFileCount(e){return e.slice(14,18).readInt32BE(0)}function getFileInfo(e){const t=getFileCount(e),n=[];let o=18;for(let r=0;r<t;r++){const t=e.slice(o,o+4).readInt32BE(0);o+=4;const r=e.slice(o,o+t).toString();o+=t;const i=e.slice(o,o+4).readInt32BE(0);o+=4;const c=e.slice(o,o+4).readInt32BE(0);o+=4,n.push({name:r,offset:i,length:c})}return n}function unpack(e,t){try{const n=getFileInfo(e),o={};for(const r of n){const{name:n,offset:i,length:c}=r;if(o[n]=e.slice(i,i+c),t){const e=path.join(t,n);mkdir.sync(path.dirname(e)),fs.writeFileSync(e,o[n])}}return o}catch(e){throw new Error("unpack wxvpkg catch error "+e)}}