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