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AAnBD,4CAmBC","sourcesContent":["import BluebirdPromise from \"bluebird-lst\"\nimport { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { readdir } from \"fs/promises\"\nimport * as path from \"path\"\nimport { readAsarHeader, NodeIntegrity } from \"./asar\"\n\nexport interface AsarIntegrityOptions {\n readonly resourcesPath: string\n readonly resourcesRelativePath: string\n}\n\nexport interface HeaderHash {\n algorithm: \"SHA256\"\n hash: string\n}\n\nexport interface AsarIntegrity {\n [key: string]: HeaderHash\n}\n\nexport async function computeData({ resourcesPath, resourcesRelativePath }: AsarIntegrityOptions): 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 => hashHeader(path.join(resourcesPath, it)))\n\n const result: AsarIntegrity = {}\n for (let i = 0; i < names.length; i++) {\n result[path.join(resourcesRelativePath, names[i])] = checksums[i]\n }\n return result\n}\n\nasync function hashHeader(file: string): Promise<HeaderHash> {\n const hash = createHash(\"sha256\")\n const { header } = await readAsarHeader(file)\n hash.update(header)\n return {\n algorithm: \"SHA256\",\n hash: hash.digest(\"hex\"),\n }\n}\n\nexport function hashFile(file: string, blockSize = 4 * 1024 * 1024): Promise<NodeIntegrity> {\n return new Promise<NodeIntegrity>((resolve, reject) => {\n const hash = createHash(\"sha256\")\n\n const blocks = new Array<string>()\n\n let blockBytes = 0\n let blockHash = createHash(\"sha256\")\n\n function updateBlockHash(chunk: Buffer) {\n let off = 0\n while (off < chunk.length) {\n const toHash = Math.min(blockSize - blockBytes, chunk.length - off)\n blockHash.update(chunk.slice(off, off + toHash))\n off += toHash\n blockBytes += toHash\n\n if (blockBytes === blockSize) {\n blocks.push(blockHash.digest(\"hex\"))\n blockHash = createHash(\"sha256\")\n blockBytes = 0\n }\n }\n }\n\n createReadStream(file)\n .on(\"data\", it => {\n // Note that `it` is a Buffer anyway so this cast is a no-op\n updateBlockHash(Buffer.from(it))\n hash.update(it)\n })\n .on(\"error\", reject)\n .on(\"end\", () => {\n if (blockBytes !== 0) {\n blocks.push(blockHash.digest(\"hex\"))\n }\n resolve({\n algorithm: \"SHA256\",\n hash: hash.digest(\"hex\"),\n blockSize,\n blocks,\n })\n })\n })\n}\n\nexport function hashFileContents(contents: Buffer | string, blockSize = 4 * 1024 * 1024): NodeIntegrity {\n const buffer = Buffer.from(contents)\n const hash = createHash(\"sha256\")\n hash.update(buffer)\n\n const blocks = new Array<string>()\n\n for (let off = 0; off < buffer.length; off += blockSize) {\n const blockHash = createHash(\"sha256\")\n blockHash.update(buffer.slice(off, off + blockSize))\n blocks.push(blockHash.digest(\"hex\"))\n }\n\n return {\n algorithm: \"SHA256\",\n hash: hash.digest(\"hex\"),\n blockSize,\n blocks,\n }\n}\n"]}