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,YAAC,AAAQ,AAAC;AAExB,AAAgB,kDAAC,AAAI,AAAC,MACnB,AAAE,GAAC,AAAO,SAAE,AAAM,AAAC,QACnB,AAAE,GAAC,AAAK,OAAE,AAAG,AAAE;AACd,AAAI,iBAAC,AAAG,AAAE;AACV,AAAO,oBAAC,AAAI,KAAC,AAAI,AAAY,AAAC,AAChC;AAAC,AAAC,WACD,AAAI,KAAC,AAAI,MAAE,EAAC,AAAG,KAAE,AAAK,AAAC,AAAC,AAC7B;AAAC,AAAC,AACJ,KAdS,AAAI,AAAe;AAc3B","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { readdir } from \"fs-extra-p\"\nimport * as path from \"path\"\n\nexport interface AsarIntegrityOptions {\n /**\n * Allows external asar files.\n *\n * @default false\n */\n readonly externalAllowed?: boolean\n}\n\nexport interface AsarIntegrity extends AsarIntegrityOptions {\n checksums: { [key: string]: string; }\n}\n\nexport async function computeData(resourcesPath: string, options?: AsarIntegrityOptions | null): Promise<AsarIntegrity> {\n // sort to produce constant result\n const names = (await readdir(resourcesPath)).filter(it => it.endsWith(\".asar\")).sort()\n const checksums = await BluebirdPromise.map(names, it => hashFile(path.join(resourcesPath, it)))\n\n const result: { [key: string]: string; } = {}\n for (let i = 0; i < names.length; i++) {\n result[names[i]] = checksums[i]\n }\n return {checksums: result, ...options}\n}\n\nfunction hashFile(file: string, algorithm: string = \"sha512\", encoding: \"hex\" | \"base64\" | \"latin1\" = \"base64\") {\n return new BluebirdPromise<string>((resolve, reject) => {\n const hash = createHash(algorithm)\n hash\n .on(\"error\", reject)\n .setEncoding(encoding)\n\n createReadStream(file)\n .on(\"error\", reject)\n .on(\"end\", () => {\n hash.end()\n resolve(hash.read() as string)\n })\n .pipe(hash, {end: false})\n })\n}"]}
|