"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getFileInfoLength=getFileInfoLength,exports.getFileIndexLength=getFileIndexLength,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,INDEX_LENGTH_BEGIN:INDEX_LENGTH_BEGIN,INDEX_LENGTH_END:INDEX_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.ConfigV10;function getFileInfoLength(e){return e.slice(INFO_LENGTH_BEGIN,INFO_LENGTH_END).readInt32BE(0)}function getFileIndexLength(e){return e.slice(INDEX_LENGTH_BEGIN,INDEX_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 I=0;I<t;I++){const t=e.slice(E,E+4).readInt32BE(0);E+=4;const I=e.slice(E,E+t).toString();E+=t;const N=e.slice(E,E+1).readIntBE(0,1,!1);E+=1;const o=e.slice(E,E+2).readIntBE(0,2,!1);E+=2;const _=e.slice(E,E+4).readInt32BE(0);E+=4;const i=e.slice(E,E+4).readInt32BE(0);E+=4,n.push({name:I,encType:N,mode:o,offset:_,length:i})}return n}function unpack(e,t){try{const n=getFileInfo(e),E={},I=18+getFileInfoLength(e)+getFileIndexLength(e);for(const N of n){const{name:n,offset:o,length:_,mode:i}=N;if(E[n]=e.slice(o+I,o+I+_),t){const e=path.join(t,n);mkdir.sync(path.dirname(e)),fs.writeFileSync(e,E[n],{mode:i.toString(8)})}}return E}catch(e){throw new Error("unpack wxvpkg catch error "+e)}}