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nC,EAA2C,QAAQ,GAAG,UAAU,CAAC,MAAjE,CAAN;AAEA,UAAM,UAAU,GAAG,MAAM,CAAC,WAAP,CAAmB,UAAU,CAAC,YAAX,CAAwB,CAAxB,CAAnB,CAAnB;AACA,UAAM,qBAAK,EAAL,EAAS,UAAT,EAAqB,CAArB,EAAwB,UAAU,CAAC,MAAnC,EAA2C,QAAQ,GAAG,UAAU,CAAC,MAAtB,GAA+B,UAAU,CAAC,MAArF,CAAN;AACA,UAAM,sBAAM,EAAN,CAAN;AAEA,WAAO,YAAY,CAAC,UAAD,CAAnB;AACD,GAVD,CAWA,OAAO,CAAP,EAAU;AACR,UAAM,sBAAM,EAAN,CAAN;AACA,UAAM,CAAN;AACD;AACF,C","sourcesContent":["import { BlockMap } from \"builder-util-runtime/out/blockMapApi\"\nimport { close, fstat, open, read } from \"fs-extra\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\nimport { inflateRawSync } from \"zlib\"\n\nexport class FileWithEmbeddedBlockMapDifferentialDownloader extends DifferentialDownloader {\n  async download(): Promise<void> {\n    const packageInfo = this.blockAwareFileInfo\n    const fileSize = packageInfo.size!!\n    const offset = fileSize - (packageInfo.blockMapSize!! + 4)\n    this.fileMetadataBuffer = await this.readRemoteBytes(offset, fileSize - 1)\n    const newBlockMap = readBlockMap(this.fileMetadataBuffer.slice(0, this.fileMetadataBuffer.length - 4))\n    await this.doDownload(await readEmbeddedBlockMapData(this.options.oldFile), newBlockMap)\n  }\n}\n\nfunction readBlockMap(data: Buffer): BlockMap {\n  return JSON.parse(inflateRawSync(data).toString())\n}\n\nasync function readEmbeddedBlockMapData(file: string): Promise<BlockMap> {\n  const fd = await open(file, \"r\")\n  try {\n    const fileSize = (await fstat(fd)).size\n    const sizeBuffer = Buffer.allocUnsafe(4)\n    await read(fd, sizeBuffer, 0, sizeBuffer.length, fileSize - sizeBuffer.length)\n\n    const dataBuffer = Buffer.allocUnsafe(sizeBuffer.readUInt32BE(0))\n    await read(fd, dataBuffer, 0, dataBuffer.length, fileSize - sizeBuffer.length - dataBuffer.length)\n    await close(fd)\n\n    return readBlockMap(dataBuffer)\n  }\n  catch (e) {\n    await close(fd)\n    throw e\n  }\n}"],"sourceRoot":""}
2