electron-updater 4.3.8 → 4.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +22 -0
  2. package/out/AppAdapter.js +19 -28
  3. package/out/AppAdapter.js.map +1 -1
  4. package/out/AppImageUpdater.js +103 -195
  5. package/out/AppImageUpdater.js.map +1 -1
  6. package/out/AppUpdater.d.ts +1 -1
  7. package/out/AppUpdater.js +517 -771
  8. package/out/AppUpdater.js.map +1 -1
  9. package/out/BaseUpdater.js +79 -103
  10. package/out/BaseUpdater.js.map +1 -1
  11. package/out/DownloadedUpdateHelper.js +150 -223
  12. package/out/DownloadedUpdateHelper.js.map +1 -1
  13. package/out/ElectronAppAdapter.js +35 -63
  14. package/out/ElectronAppAdapter.js.map +1 -1
  15. package/out/MacUpdater.js +132 -201
  16. package/out/MacUpdater.js.map +1 -1
  17. package/out/NoOpLogger.d.ts +6 -0
  18. package/out/NoOpLogger.js +19 -0
  19. package/out/NoOpLogger.js.map +1 -0
  20. package/out/NsisUpdater.js +199 -345
  21. package/out/NsisUpdater.js.map +1 -1
  22. package/out/differentialDownloader/DataSplitter.js +180 -252
  23. package/out/differentialDownloader/DataSplitter.js.map +1 -1
  24. package/out/differentialDownloader/DifferentialDownloader.d.ts +1 -1
  25. package/out/differentialDownloader/DifferentialDownloader.js +242 -355
  26. package/out/differentialDownloader/DifferentialDownloader.js.map +1 -1
  27. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js +29 -65
  28. package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js.map +1 -1
  29. package/out/differentialDownloader/GenericDifferentialDownloader.js +7 -21
  30. package/out/differentialDownloader/GenericDifferentialDownloader.js.map +1 -1
  31. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js +79 -107
  32. package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js.map +1 -1
  33. package/out/differentialDownloader/downloadPlanBuilder.js +99 -123
  34. package/out/differentialDownloader/downloadPlanBuilder.js.map +1 -1
  35. package/out/differentialDownloader/multipleRangeDownloader.js +99 -148
  36. package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
  37. package/out/electronHttpExecutor.js +73 -106
  38. package/out/electronHttpExecutor.js.map +1 -1
  39. package/out/event.d.ts +35 -0
  40. package/out/event.js +39 -0
  41. package/out/event.js.map +1 -0
  42. package/out/log.d.ts +11 -0
  43. package/out/log.js +19 -0
  44. package/out/log.js.map +1 -0
  45. package/out/main.d.ts +1 -3
  46. package/out/main.js +60 -196
  47. package/out/main.js.map +1 -1
  48. package/out/providerFactory.js +49 -105
  49. package/out/providerFactory.js.map +1 -1
  50. package/out/providers/BintrayProvider.d.ts +2 -2
  51. package/out/providers/BintrayProvider.js +40 -95
  52. package/out/providers/BintrayProvider.js.map +1 -1
  53. package/out/providers/GenericProvider.d.ts +2 -2
  54. package/out/providers/GenericProvider.js +46 -80
  55. package/out/providers/GenericProvider.js.map +1 -1
  56. package/out/providers/GitHubProvider.d.ts +2 -2
  57. package/out/providers/GitHubProvider.js +122 -201
  58. package/out/providers/GitHubProvider.js.map +1 -1
  59. package/out/providers/PrivateGitHubProvider.js +87 -165
  60. package/out/providers/PrivateGitHubProvider.js.map +1 -1
  61. package/out/providers/Provider.js +122 -173
  62. package/out/providers/Provider.js.map +1 -1
  63. package/out/util.d.ts +5 -0
  64. package/out/util.js +42 -0
  65. package/out/util.js.map +1 -0
  66. package/out/windowsExecutableCodeSignatureVerifier.js +99 -139
  67. package/out/windowsExecutableCodeSignatureVerifier.js.map +1 -1
  68. package/package.json +33 -31
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/differentialDownloader/DifferentialDownloader.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;;AAIA;AAAA;;AAAA;AAAA;AAAA;;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iC,MAAjC,CAAL,EAA+C;AAC7C;AACD;;AAED,QAAA,QAAQ,CAAC,EAAT,CAAY,MAAZ,EAAoB,WAApB;AACA,QAAA,QAAQ,CAAC,EAAT,CAAY,KAAZ,EAAmB,MAAM,OAAO,EAAhC;AACD,OAPe,CAAhB;AAQA,WAAK,YAAL,CAAkB,0BAAlB,CAA6C,OAA7C,EAAsD,MAAtD;AACA,MAAA,OAAO,CAAC,GAAR;AACD,KAXM,CAAP;AAYD;;AAnRyC;;;;AAsR5C,SAAS,WAAT,CAAqB,KAArB,EAAoC,MAAM,GAAG,KAA7C,EAAkD;AAChD,SAAO,IAAI,IAAI,CAAC,YAAT,CAAsB,IAAtB,EAA4B,MAA5B,CAAmC,CAAC,KAAK,GAAG,IAAT,EAAe,OAAf,CAAuB,CAAvB,CAAnC,IAAuE,MAA9E;AACD,C,CAED;;;AACA,SAAS,WAAT,CAAqB,GAArB,EAAgC;AAC9B,QAAM,KAAK,GAAG,GAAG,CAAC,OAAJ,CAAY,GAAZ,CAAd;AACA,SAAO,KAAK,GAAG,CAAR,GAAY,GAAZ,GAAkB,GAAG,CAAC,SAAJ,CAAc,CAAd,EAAiB,KAAjB,CAAzB;AACD,C","sourcesContent":["import { BlockMapDataHolder, createHttpError, DigestTransform, HttpExecutor, configureRequestUrl, configureRequestOptions } from \"builder-util-runtime\"\nimport { BlockMap } from \"builder-util-runtime/out/blockMapApi\"\nimport { close, open } from \"fs-extra\"\nimport { createWriteStream } from \"fs\"\nimport { OutgoingHttpHeaders, RequestOptions } from \"http\"\nimport { ProgressInfo, CancellationToken } from \"builder-util-runtime\"\nimport { Logger } from \"../main\"\nimport { copyData } from \"./DataSplitter\"\nimport { URL } from \"url\"\nimport { computeOperations, Operation, OperationKind } from \"./downloadPlanBuilder\"\nimport { checkIsRangesSupported, executeTasksUsingMultipleRangeRequests } from \"./multipleRangeDownloader\"\nimport { ProgressDifferentialDownloadCallbackTransform, ProgressDifferentialDownloadInfo } from \"./ProgressDifferentialDownloadCallbackTransform\"\n\nexport interface DifferentialDownloaderOptions {\n readonly oldFile: string\n readonly newUrl: URL\n readonly logger: Logger\n readonly newFile: string\n\n readonly requestHeaders: OutgoingHttpHeaders | null\n\n readonly isUseMultipleRangeRequest?: boolean\n\n readonly cancellationToken: CancellationToken\n onProgress?(progress: ProgressInfo): void\n}\n\nexport abstract class DifferentialDownloader {\n fileMetadataBuffer: Buffer | null = null\n\n private readonly logger: Logger\n\n // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected\n constructor(protected readonly blockAwareFileInfo: BlockMapDataHolder, readonly httpExecutor: HttpExecutor<any>, readonly options: DifferentialDownloaderOptions) {\n this.logger = options.logger\n }\n\n createRequestOptions(): RequestOptions {\n const result = {\n headers: {\n ...this.options.requestHeaders,\n accept: \"*/*\",\n },\n }\n configureRequestUrl(this.options.newUrl, result)\n // user-agent, cache-control and other common options\n configureRequestOptions(result)\n return result\n }\n\n protected doDownload(oldBlockMap: BlockMap, newBlockMap: BlockMap): Promise<any> {\n // we don't check other metadata like compressionMethod - generic check that it is make sense to differentially update is suitable for it\n if (oldBlockMap.version !== newBlockMap.version) {\n throw new Error(`version is different (${oldBlockMap.version} - ${newBlockMap.version}), full download is required`)\n }\n\n const logger = this.logger\n const operations = computeOperations(oldBlockMap, newBlockMap, logger)\n if (logger.debug != null) {\n logger.debug(JSON.stringify(operations, null, 2))\n }\n\n let downloadSize = 0\n let copySize = 0\n for (const operation of operations) {\n const length = operation.end - operation.start\n if (operation.kind === OperationKind.DOWNLOAD) {\n downloadSize += length\n }\n else {\n copySize += length\n }\n }\n\n const newSize = this.blockAwareFileInfo.size\n if ((downloadSize + copySize + (this.fileMetadataBuffer == null ? 0 : this.fileMetadataBuffer.length)) !== newSize) {\n throw new Error(`Internal error, size mismatch: downloadSize: ${downloadSize}, copySize: ${copySize}, newSize: ${newSize}`)\n }\n\n logger.info(`Full: ${formatBytes(newSize)}, To download: ${formatBytes(downloadSize)} (${Math.round(downloadSize / (newSize / 100))}%)`)\n\n return this.downloadFile(operations)\n }\n\n private downloadFile(tasks: Array<Operation>): Promise<any> {\n const fdList: Array<OpenedFile> = []\n const closeFiles = (): Promise<Array<void>> => {\n return Promise.all(fdList.map(openedFile => {\n return close(openedFile.descriptor)\n .catch(e => {\n this.logger.error(`cannot close file \"${openedFile.path}\": ${e}`)\n })\n }))\n }\n return this.doDownloadFile(tasks, fdList)\n .then(closeFiles)\n .catch(e => {\n // then must be after catch here (since then always throws error)\n return closeFiles()\n .catch(closeFilesError => {\n // closeFiles never throw error, but just to be sure\n try {\n this.logger.error(`cannot close files: ${closeFilesError}`)\n }\n catch (errorOnLog) {\n try {\n console.error(errorOnLog)\n }\n catch (ignored) {\n // ok, give up and ignore error\n }\n }\n throw e\n })\n .then(() => {\n throw e\n })\n })\n }\n\n private async doDownloadFile(tasks: Array<Operation>, fdList: Array<OpenedFile>): Promise<any> {\n const oldFileFd = await open(this.options.oldFile, \"r\")\n fdList.push({descriptor: oldFileFd, path: this.options.oldFile})\n const newFileFd = await open(this.options.newFile, \"w\")\n fdList.push({descriptor: newFileFd, path: this.options.newFile})\n const fileOut = createWriteStream(this.options.newFile, {fd: newFileFd})\n await new Promise((resolve, reject) => {\n const streams: Array<any> = []\n\n // Create our download info transformer if we have one\n let downloadInfoTransform: ProgressDifferentialDownloadCallbackTransform | undefined = undefined\n if (!this.options.isUseMultipleRangeRequest && this.options.onProgress) { // TODO: Does not support multiple ranges (someone feel free to PR this!)\n const expectedByteCounts: Array<number> = []\n let grandTotalBytes = 0\n\n for (const task of tasks) {\n if (task.kind === OperationKind.DOWNLOAD) {\n expectedByteCounts.push(task.end - task.start)\n grandTotalBytes += task.end - task.start\n }\n }\n\n const progressDifferentialDownloadInfo: ProgressDifferentialDownloadInfo = {\n expectedByteCounts: expectedByteCounts,\n grandTotal: grandTotalBytes\n }\n\n downloadInfoTransform = new ProgressDifferentialDownloadCallbackTransform(progressDifferentialDownloadInfo, this.options.cancellationToken, this.options.onProgress)\n streams.push(downloadInfoTransform)\n }\n\n const digestTransform = new DigestTransform(this.blockAwareFileInfo.sha512)\n // to simply debug, do manual validation to allow file to be fully written\n digestTransform.isValidateOnEnd = false\n streams.push(digestTransform)\n\n // noinspection JSArrowFunctionCanBeReplacedWithShorthand\n fileOut.on(\"finish\", () => {\n (fileOut.close as any)(() => {\n // remove from fd list because closed successfully\n fdList.splice(1, 1)\n try {\n digestTransform.validate()\n }\n catch (e) {\n reject(e)\n return\n }\n\n resolve(undefined)\n })\n })\n\n streams.push(fileOut)\n\n let lastStream = null\n for (const stream of streams) {\n stream.on(\"error\", reject)\n if (lastStream == null) {\n lastStream = stream\n }\n else {\n lastStream = lastStream.pipe(stream)\n }\n }\n\n const firstStream = streams[0]\n\n let w: any\n if (this.options.isUseMultipleRangeRequest) {\n w = executeTasksUsingMultipleRangeRequests(this, tasks, firstStream, oldFileFd, reject)\n w(0)\n return\n }\n\n let downloadOperationCount = 0\n let actualUrl: string | null = null\n this.logger.info(`Differential download: ${this.options.newUrl}`)\n\n const requestOptions = this.createRequestOptions();\n (requestOptions as any).redirect = \"manual\"\n\n w = (index: number): void => {\n if (index >= tasks.length) {\n if (this.fileMetadataBuffer != null) {\n firstStream.write(this.fileMetadataBuffer)\n }\n firstStream.end()\n return\n }\n\n const operation = tasks[index++]\n if (operation.kind === OperationKind.COPY) {\n // We are copying, let's not send status updates to the UI\n if (downloadInfoTransform) {\n downloadInfoTransform.beginFileCopy()\n }\n\n copyData(operation, firstStream, oldFileFd, reject, () => w(index))\n return\n }\n\n const range = `bytes=${operation.start}-${operation.end - 1}`\n requestOptions.headers!!.range = range\n\n const debug = this.logger.debug\n if (debug != null) {\n debug(`download range: ${range}`)\n }\n\n // We are starting to download\n if (downloadInfoTransform) {\n downloadInfoTransform.beginRangeDownload()\n }\n\n const request = this.httpExecutor.createRequest(requestOptions, response => {\n // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.\n if (response.statusCode >= 400) {\n reject(createHttpError(response))\n }\n\n response.pipe(firstStream, {\n end: false\n })\n response.once(\"end\", () => {\n // Pass on that we are downloading a segment\n if (downloadInfoTransform) {\n downloadInfoTransform.endRangeDownload()\n }\n\n if (++downloadOperationCount === 100) {\n downloadOperationCount = 0\n setTimeout(() => w(index), 1000)\n }\n else {\n w(index)\n }\n })\n })\n request.on(\"redirect\", (statusCode: number, method: string, redirectUrl: string) => {\n this.logger.info(`Redirect to ${removeQuery(redirectUrl)}`)\n actualUrl = redirectUrl\n configureRequestUrl(new URL(actualUrl), requestOptions)\n request.followRedirect()\n })\n this.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n\n w(0)\n })\n }\n\n protected async readRemoteBytes(start: number, endInclusive: number): Promise<Buffer> {\n const buffer = Buffer.allocUnsafe((endInclusive + 1) - start)\n const requestOptions = this.createRequestOptions()\n requestOptions.headers!!.range = `bytes=${start}-${endInclusive}`\n let position = 0\n await this.request(requestOptions, chunk => {\n chunk.copy(buffer, position)\n position += chunk.length\n })\n\n if (position !== buffer.length) {\n throw new Error(`Received data length ${position} is not equal to expected ${buffer.length}`)\n }\n return buffer\n }\n\n private request(requestOptions: RequestOptions, dataHandler: (chunk: Buffer) => void): Promise<void> {\n return new Promise((resolve, reject) => {\n const request = this.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.on(\"data\", dataHandler)\n response.on(\"end\", () => resolve())\n })\n this.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n })\n }\n}\n\nfunction formatBytes(value: number, symbol = \" KB\"): string {\n return new Intl.NumberFormat(\"en\").format((value / 1024).toFixed(2) as any) + symbol\n}\n\n// safety\nfunction removeQuery(url: string): string {\n const index = url.indexOf(\"?\")\n return index < 0 ? url : url.substring(0, index)\n}\n\ninterface OpenedFile {\n readonly descriptor: number\n readonly path: string\n}\n"],"sourceRoot":""}
1
+ {"version":3,"file":"DifferentialDownloader.js","sourceRoot":"","sources":["../../src/different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;AAED,SAAS,WAAW,CAAC,KAAa,EAAE,MAAM,GAAG,KAAK;IAChD,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAQ,CAAC,GAAG,MAAM,CAAA;AACtF,CAAC;AAED,SAAS;AACT,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC9B,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AAClD,CAAC","sourcesContent":["import { BlockMapDataHolder, createHttpError, DigestTransform, HttpExecutor, configureRequestUrl, configureRequestOptions } from \"builder-util-runtime\"\nimport { BlockMap } from \"builder-util-runtime/out/blockMapApi\"\nimport { close, open } from \"fs-extra\"\nimport { createWriteStream } from \"fs\"\nimport { OutgoingHttpHeaders, RequestOptions } from \"http\"\nimport { ProgressInfo, CancellationToken } from \"builder-util-runtime\"\nimport { Logger } from \"../main\"\nimport { copyData } from \"./DataSplitter\"\nimport { URL } from \"url\"\nimport { computeOperations, Operation, OperationKind } from \"./downloadPlanBuilder\"\nimport { checkIsRangesSupported, executeTasksUsingMultipleRangeRequests } from \"./multipleRangeDownloader\"\nimport { ProgressDifferentialDownloadCallbackTransform, ProgressDifferentialDownloadInfo } from \"./ProgressDifferentialDownloadCallbackTransform\"\n\nexport interface DifferentialDownloaderOptions {\n readonly oldFile: string\n readonly newUrl: URL\n readonly logger: Logger\n readonly newFile: string\n\n readonly requestHeaders: OutgoingHttpHeaders | null\n\n readonly isUseMultipleRangeRequest?: boolean\n\n readonly cancellationToken: CancellationToken\n onProgress?: (progress: ProgressInfo) => void\n}\n\nexport abstract class DifferentialDownloader {\n fileMetadataBuffer: Buffer | null = null\n\n private readonly logger: Logger\n\n // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected\n constructor(protected readonly blockAwareFileInfo: BlockMapDataHolder, readonly httpExecutor: HttpExecutor<any>, readonly options: DifferentialDownloaderOptions) {\n this.logger = options.logger\n }\n\n createRequestOptions(): RequestOptions {\n const result = {\n headers: {\n ...this.options.requestHeaders,\n accept: \"*/*\",\n },\n }\n configureRequestUrl(this.options.newUrl, result)\n // user-agent, cache-control and other common options\n configureRequestOptions(result)\n return result\n }\n\n protected doDownload(oldBlockMap: BlockMap, newBlockMap: BlockMap): Promise<any> {\n // we don't check other metadata like compressionMethod - generic check that it is make sense to differentially update is suitable for it\n if (oldBlockMap.version !== newBlockMap.version) {\n throw new Error(`version is different (${oldBlockMap.version} - ${newBlockMap.version}), full download is required`)\n }\n\n const logger = this.logger\n const operations = computeOperations(oldBlockMap, newBlockMap, logger)\n if (logger.debug != null) {\n logger.debug(JSON.stringify(operations, null, 2))\n }\n\n let downloadSize = 0\n let copySize = 0\n for (const operation of operations) {\n const length = operation.end - operation.start\n if (operation.kind === OperationKind.DOWNLOAD) {\n downloadSize += length\n } else {\n copySize += length\n }\n }\n\n const newSize = this.blockAwareFileInfo.size\n if (downloadSize + copySize + (this.fileMetadataBuffer == null ? 0 : this.fileMetadataBuffer.length) !== newSize) {\n throw new Error(`Internal error, size mismatch: downloadSize: ${downloadSize}, copySize: ${copySize}, newSize: ${newSize}`)\n }\n\n logger.info(`Full: ${formatBytes(newSize)}, To download: ${formatBytes(downloadSize)} (${Math.round(downloadSize / (newSize / 100))}%)`)\n\n return this.downloadFile(operations)\n }\n\n private downloadFile(tasks: Array<Operation>): Promise<any> {\n const fdList: Array<OpenedFile> = []\n const closeFiles = (): Promise<Array<void>> => {\n return Promise.all(\n fdList.map(openedFile => {\n return close(openedFile.descriptor).catch(e => {\n this.logger.error(`cannot close file \"${openedFile.path}\": ${e}`)\n })\n })\n )\n }\n return this.doDownloadFile(tasks, fdList)\n .then(closeFiles)\n .catch(e => {\n // then must be after catch here (since then always throws error)\n return closeFiles()\n .catch(closeFilesError => {\n // closeFiles never throw error, but just to be sure\n try {\n this.logger.error(`cannot close files: ${closeFilesError}`)\n } catch (errorOnLog) {\n try {\n console.error(errorOnLog)\n } catch (ignored) {\n // ok, give up and ignore error\n }\n }\n throw e\n })\n .then(() => {\n throw e\n })\n })\n }\n\n private async doDownloadFile(tasks: Array<Operation>, fdList: Array<OpenedFile>): Promise<any> {\n const oldFileFd = await open(this.options.oldFile, \"r\")\n fdList.push({ descriptor: oldFileFd, path: this.options.oldFile })\n const newFileFd = await open(this.options.newFile, \"w\")\n fdList.push({ descriptor: newFileFd, path: this.options.newFile })\n const fileOut = createWriteStream(this.options.newFile, { fd: newFileFd })\n await new Promise((resolve, reject) => {\n const streams: Array<any> = []\n\n // Create our download info transformer if we have one\n let downloadInfoTransform: ProgressDifferentialDownloadCallbackTransform | undefined = undefined\n if (!this.options.isUseMultipleRangeRequest && this.options.onProgress) {\n // TODO: Does not support multiple ranges (someone feel free to PR this!)\n const expectedByteCounts: Array<number> = []\n let grandTotalBytes = 0\n\n for (const task of tasks) {\n if (task.kind === OperationKind.DOWNLOAD) {\n expectedByteCounts.push(task.end - task.start)\n grandTotalBytes += task.end - task.start\n }\n }\n\n const progressDifferentialDownloadInfo: ProgressDifferentialDownloadInfo = {\n expectedByteCounts: expectedByteCounts,\n grandTotal: grandTotalBytes,\n }\n\n downloadInfoTransform = new ProgressDifferentialDownloadCallbackTransform(progressDifferentialDownloadInfo, this.options.cancellationToken, this.options.onProgress)\n streams.push(downloadInfoTransform)\n }\n\n const digestTransform = new DigestTransform(this.blockAwareFileInfo.sha512)\n // to simply debug, do manual validation to allow file to be fully written\n digestTransform.isValidateOnEnd = false\n streams.push(digestTransform)\n\n // noinspection JSArrowFunctionCanBeReplacedWithShorthand\n fileOut.on(\"finish\", () => {\n ;(fileOut.close as any)(() => {\n // remove from fd list because closed successfully\n fdList.splice(1, 1)\n try {\n digestTransform.validate()\n } catch (e) {\n reject(e)\n return\n }\n\n resolve(undefined)\n })\n })\n\n streams.push(fileOut)\n\n let lastStream = null\n for (const stream of streams) {\n stream.on(\"error\", reject)\n if (lastStream == null) {\n lastStream = stream\n } else {\n lastStream = lastStream.pipe(stream)\n }\n }\n\n const firstStream = streams[0]\n\n let w: any\n if (this.options.isUseMultipleRangeRequest) {\n w = executeTasksUsingMultipleRangeRequests(this, tasks, firstStream, oldFileFd, reject)\n w(0)\n return\n }\n\n let downloadOperationCount = 0\n let actualUrl: string | null = null\n this.logger.info(`Differential download: ${this.options.newUrl}`)\n\n const requestOptions = this.createRequestOptions()\n ;(requestOptions as any).redirect = \"manual\"\n\n w = (index: number): void => {\n if (index >= tasks.length) {\n if (this.fileMetadataBuffer != null) {\n firstStream.write(this.fileMetadataBuffer)\n }\n firstStream.end()\n return\n }\n\n const operation = tasks[index++]\n if (operation.kind === OperationKind.COPY) {\n // We are copying, let's not send status updates to the UI\n if (downloadInfoTransform) {\n downloadInfoTransform.beginFileCopy()\n }\n\n copyData(operation, firstStream, oldFileFd, reject, () => w(index))\n return\n }\n\n const range = `bytes=${operation.start}-${operation.end - 1}`\n requestOptions.headers!.range = range\n\n this.logger?.debug?.(`download range: ${range}`)\n\n // We are starting to download\n if (downloadInfoTransform) {\n downloadInfoTransform.beginRangeDownload()\n }\n\n const request = this.httpExecutor.createRequest(requestOptions, response => {\n // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.\n if (response.statusCode >= 400) {\n reject(createHttpError(response))\n }\n\n response.pipe(firstStream, {\n end: false,\n })\n response.once(\"end\", () => {\n // Pass on that we are downloading a segment\n if (downloadInfoTransform) {\n downloadInfoTransform.endRangeDownload()\n }\n\n if (++downloadOperationCount === 100) {\n downloadOperationCount = 0\n setTimeout(() => w(index), 1000)\n } else {\n w(index)\n }\n })\n })\n request.on(\"redirect\", (statusCode: number, method: string, redirectUrl: string) => {\n this.logger.info(`Redirect to ${removeQuery(redirectUrl)}`)\n actualUrl = redirectUrl\n configureRequestUrl(new URL(actualUrl), requestOptions)\n request.followRedirect()\n })\n this.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n\n w(0)\n })\n }\n\n protected async readRemoteBytes(start: number, endInclusive: number): Promise<Buffer> {\n const buffer = Buffer.allocUnsafe(endInclusive + 1 - start)\n const requestOptions = this.createRequestOptions()\n requestOptions.headers!.range = `bytes=${start}-${endInclusive}`\n let position = 0\n await this.request(requestOptions, chunk => {\n chunk.copy(buffer, position)\n position += chunk.length\n })\n\n if (position !== buffer.length) {\n throw new Error(`Received data length ${position} is not equal to expected ${buffer.length}`)\n }\n return buffer\n }\n\n private request(requestOptions: RequestOptions, dataHandler: (chunk: Buffer) => void): Promise<void> {\n return new Promise((resolve, reject) => {\n const request = this.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.on(\"data\", dataHandler)\n response.on(\"end\", () => resolve())\n })\n this.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n })\n }\n}\n\nfunction formatBytes(value: number, symbol = \" KB\"): string {\n return new Intl.NumberFormat(\"en\").format((value / 1024).toFixed(2) as any) + symbol\n}\n\n// safety\nfunction removeQuery(url: string): string {\n const index = url.indexOf(\"?\")\n return index < 0 ? url : url.substring(0, index)\n}\n\ninterface OpenedFile {\n readonly descriptor: number\n readonly path: string\n}\n"]}
@@ -1,73 +1,37 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.FileWithEmbeddedBlockMapDifferentialDownloader = void 0;
7
-
8
- function _fsExtra() {
9
- const data = require("fs-extra");
10
-
11
- _fsExtra = function () {
12
- return data;
13
- };
14
-
15
- return data;
4
+ const fs_extra_1 = require("fs-extra");
5
+ const DifferentialDownloader_1 = require("./DifferentialDownloader");
6
+ const zlib_1 = require("zlib");
7
+ class FileWithEmbeddedBlockMapDifferentialDownloader extends DifferentialDownloader_1.DifferentialDownloader {
8
+ async download() {
9
+ const packageInfo = this.blockAwareFileInfo;
10
+ const fileSize = packageInfo.size;
11
+ const offset = fileSize - (packageInfo.blockMapSize + 4);
12
+ this.fileMetadataBuffer = await this.readRemoteBytes(offset, fileSize - 1);
13
+ const newBlockMap = readBlockMap(this.fileMetadataBuffer.slice(0, this.fileMetadataBuffer.length - 4));
14
+ await this.doDownload(await readEmbeddedBlockMapData(this.options.oldFile), newBlockMap);
15
+ }
16
16
  }
17
-
18
- function _DifferentialDownloader() {
19
- const data = require("./DifferentialDownloader");
20
-
21
- _DifferentialDownloader = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _zlib() {
29
- const data = require("zlib");
30
-
31
- _zlib = function () {
32
- return data;
33
- };
34
-
35
- return data;
36
- }
37
-
38
- class FileWithEmbeddedBlockMapDifferentialDownloader extends _DifferentialDownloader().DifferentialDownloader {
39
- async download() {
40
- const packageInfo = this.blockAwareFileInfo;
41
- const fileSize = packageInfo.size;
42
- const offset = fileSize - (packageInfo.blockMapSize + 4);
43
- this.fileMetadataBuffer = await this.readRemoteBytes(offset, fileSize - 1);
44
- const newBlockMap = readBlockMap(this.fileMetadataBuffer.slice(0, this.fileMetadataBuffer.length - 4));
45
- await this.doDownload(await readEmbeddedBlockMapData(this.options.oldFile), newBlockMap);
46
- }
47
-
48
- }
49
-
50
17
  exports.FileWithEmbeddedBlockMapDifferentialDownloader = FileWithEmbeddedBlockMapDifferentialDownloader;
51
-
52
18
  function readBlockMap(data) {
53
- return JSON.parse((0, _zlib().inflateRawSync)(data).toString());
19
+ return JSON.parse(zlib_1.inflateRawSync(data).toString());
54
20
  }
55
-
56
21
  async function readEmbeddedBlockMapData(file) {
57
- const fd = await (0, _fsExtra().open)(file, "r");
58
-
59
- try {
60
- const fileSize = (await (0, _fsExtra().fstat)(fd)).size;
61
- const sizeBuffer = Buffer.allocUnsafe(4);
62
- await (0, _fsExtra().read)(fd, sizeBuffer, 0, sizeBuffer.length, fileSize - sizeBuffer.length);
63
- const dataBuffer = Buffer.allocUnsafe(sizeBuffer.readUInt32BE(0));
64
- await (0, _fsExtra().read)(fd, dataBuffer, 0, dataBuffer.length, fileSize - sizeBuffer.length - dataBuffer.length);
65
- await (0, _fsExtra().close)(fd);
66
- return readBlockMap(dataBuffer);
67
- } catch (e) {
68
- await (0, _fsExtra().close)(fd);
69
- throw e;
70
- }
71
- }
72
- // __ts-babel@6.0.4
22
+ const fd = await fs_extra_1.open(file, "r");
23
+ try {
24
+ const fileSize = (await fs_extra_1.fstat(fd)).size;
25
+ const sizeBuffer = Buffer.allocUnsafe(4);
26
+ await fs_extra_1.read(fd, sizeBuffer, 0, sizeBuffer.length, fileSize - sizeBuffer.length);
27
+ const dataBuffer = Buffer.allocUnsafe(sizeBuffer.readUInt32BE(0));
28
+ await fs_extra_1.read(fd, dataBuffer, 0, dataBuffer.length, fileSize - sizeBuffer.length - dataBuffer.length);
29
+ await fs_extra_1.close(fd);
30
+ return readBlockMap(dataBuffer);
31
+ }
32
+ catch (e) {
33
+ await fs_extra_1.close(fd);
34
+ throw e;
35
+ }
36
+ }
73
37
  //# sourceMappingURL=FileWithEmbeddedBlockMapDifferentialDownloader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.ts"],"names":[],"mappings":";;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEM,MAAO,8CAAP,SAA8D,gDAA9D,CAAoF;AACxF,QAAM,QAAN,GAAc;AACZ,UAAM,WAAW,GAAG,KAAK,kBAAzB;AACA,UAAM,QAAQ,GAAG,WAAW,CAAC,IAA7B;AACA,UAAM,MAAM,GAAG,QAAQ,IAAI,WAAW,CAAC,YAAZ,GAA6B,CAAjC,CAAvB;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ACD;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":""}
1
+ {"version":3,"file":"FileWithEmbeddedBlockMapDifferentialDownloader.js","sourceRoot":"","sources":["../../src/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.ts"],"names":[],"mappings":";;;AACA,uCAAmD;AACnD,qEAAiE;AACjE,+BAAqC;AAErC,MAAa,8CAA+C,SAAQ,+CAAsB;IACxF,KAAK,CAAC,QAAQ;QACZ,MAAM,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAA;QAC3C,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAK,CAAA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AM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;QAClG,MAAM,gBAAK,CAAC,EAAE,CAAC,CAAA;QAEf,OAAO,YAAY,CAAC,UAAU,CAAC,CAAA;KAChC;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,gBAAK,CAAC,EAAE,CAAC,CAAA;QACf,MAAM,CAAC,CAAA;KACR;AACH,CAAC","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 } catch (e) {\n await close(fd)\n throw e\n }\n}\n"]}
@@ -1,25 +1,11 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.GenericDifferentialDownloader = void 0;
7
-
8
- function _DifferentialDownloader() {
9
- const data = require("./DifferentialDownloader");
10
-
11
- _DifferentialDownloader = function () {
12
- return data;
13
- };
14
-
15
- return data;
4
+ const DifferentialDownloader_1 = require("./DifferentialDownloader");
5
+ class GenericDifferentialDownloader extends DifferentialDownloader_1.DifferentialDownloader {
6
+ download(oldBlockMap, newBlockMap) {
7
+ return this.doDownload(oldBlockMap, newBlockMap);
8
+ }
16
9
  }
17
-
18
- class GenericDifferentialDownloader extends _DifferentialDownloader().DifferentialDownloader {
19
- download(oldBlockMap, newBlockMap) {
20
- return this.doDownload(oldBlockMap, newBlockMap);
21
- }
22
-
23
- } exports.GenericDifferentialDownloader = GenericDifferentialDownloader;
24
- // __ts-babel@6.0.4
10
+ exports.GenericDifferentialDownloader = GenericDifferentialDownloader;
25
11
  //# sourceMappingURL=GenericDifferentialDownloader.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/differentialDownloader/GenericDifferentialDownloader.ts"],"names":[],"mappings":";;;;;;;AACA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAEM,MAAO,6BAAP,SAA6C,gDAA7C,CAAmE;AACvE,EAAA,QAAQ,CAAC,WAAD,EAAwB,WAAxB,EAA6C;AACnD,WAAO,KAAK,UAAL,CAAgB,WAAhB,EAA6B,WAA7B,CAAP;AACD;;AAHsE,C","sourcesContent":["import { BlockMap } from \"builder-util-runtime/out/blockMapApi\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\n\nexport class GenericDifferentialDownloader extends DifferentialDownloader {\n download(oldBlockMap: BlockMap, newBlockMap: BlockMap): Promise<any> {\n return this.doDownload(oldBlockMap, newBlockMap)\n }\n}"],"sourceRoot":""}
1
+ {"version":3,"file":"GenericDifferentialDownloader.js","sourceRoot":"","sources":["../../src/differentialDownloader/GenericDifferentialDownloader.ts"],"names":[],"mappings":";;;AACA,qEAAiE;AAEjE,MAAa,6BAA8B,SAAQ,+CAAsB;IACvE,QAAQ,CAAC,WAAqB,EAAE,WAAqB;QACnD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;IAClD,CAAC;CACF;AAJD,sEAIC","sourcesContent":["import { BlockMap } from \"builder-util-runtime/out/blockMapApi\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\n\nexport class GenericDifferentialDownloader extends DifferentialDownloader {\n download(oldBlockMap: BlockMap, newBlockMap: BlockMap): Promise<any> {\n return this.doDownload(oldBlockMap, newBlockMap)\n }\n}\n"]}
@@ -1,118 +1,90 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ProgressDifferentialDownloadCallbackTransform = void 0;
7
-
8
- function _stream() {
9
- const data = require("stream");
10
-
11
- _stream = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
4
+ const stream_1 = require("stream");
18
5
  var OperationKind;
19
-
20
6
  (function (OperationKind) {
21
- OperationKind[OperationKind["COPY"] = 0] = "COPY";
22
- OperationKind[OperationKind["DOWNLOAD"] = 1] = "DOWNLOAD";
7
+ OperationKind[OperationKind["COPY"] = 0] = "COPY";
8
+ OperationKind[OperationKind["DOWNLOAD"] = 1] = "DOWNLOAD";
23
9
  })(OperationKind || (OperationKind = {}));
24
-
25
- class ProgressDifferentialDownloadCallbackTransform extends _stream().Transform {
26
- constructor(progressDifferentialDownloadInfo, cancellationToken, onProgress) {
27
- super();
28
- this.progressDifferentialDownloadInfo = progressDifferentialDownloadInfo;
29
- this.cancellationToken = cancellationToken;
30
- this.onProgress = onProgress;
31
- this.start = Date.now();
32
- this.transferred = 0;
33
- this.delta = 0;
34
- this.expectedBytes = 0;
35
- this.index = 0;
36
- this.operationType = OperationKind.COPY;
37
- this.nextUpdate = this.start + 1000;
38
- }
39
-
40
- _transform(chunk, encoding, callback) {
41
- if (this.cancellationToken.cancelled) {
42
- callback(new Error("cancelled"), null);
43
- return;
44
- } // Don't send progress update when copying from disk
45
-
46
-
47
- if (this.operationType == OperationKind.COPY) {
48
- callback(null, chunk);
49
- return;
10
+ class ProgressDifferentialDownloadCallbackTransform extends stream_1.Transform {
11
+ constructor(progressDifferentialDownloadInfo, cancellationToken, onProgress) {
12
+ super();
13
+ this.progressDifferentialDownloadInfo = progressDifferentialDownloadInfo;
14
+ this.cancellationToken = cancellationToken;
15
+ this.onProgress = onProgress;
16
+ this.start = Date.now();
17
+ this.transferred = 0;
18
+ this.delta = 0;
19
+ this.expectedBytes = 0;
20
+ this.index = 0;
21
+ this.operationType = OperationKind.COPY;
22
+ this.nextUpdate = this.start + 1000;
23
+ }
24
+ _transform(chunk, encoding, callback) {
25
+ if (this.cancellationToken.cancelled) {
26
+ callback(new Error("cancelled"), null);
27
+ return;
28
+ }
29
+ // Don't send progress update when copying from disk
30
+ if (this.operationType == OperationKind.COPY) {
31
+ callback(null, chunk);
32
+ return;
33
+ }
34
+ this.transferred += chunk.length;
35
+ this.delta += chunk.length;
36
+ const now = Date.now();
37
+ if (now >= this.nextUpdate &&
38
+ this.transferred !== this.expectedBytes /* will be emitted by endRangeDownload() */ &&
39
+ this.transferred !== this.progressDifferentialDownloadInfo.grandTotal /* will be emitted on _flush */) {
40
+ this.nextUpdate = now + 1000;
41
+ this.onProgress({
42
+ total: this.progressDifferentialDownloadInfo.grandTotal,
43
+ delta: this.delta,
44
+ transferred: this.transferred,
45
+ percent: (this.transferred / this.progressDifferentialDownloadInfo.grandTotal) * 100,
46
+ bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000)),
47
+ });
48
+ this.delta = 0;
49
+ }
50
+ callback(null, chunk);
51
+ }
52
+ beginFileCopy() {
53
+ this.operationType = OperationKind.COPY;
50
54
  }
51
-
52
- this.transferred += chunk.length;
53
- this.delta += chunk.length;
54
- const now = Date.now();
55
-
56
- if (now >= this.nextUpdate && this.transferred !== this.expectedBytes
57
- /* will be emitted by endRangeDownload() */
58
- && this.transferred !== this.progressDifferentialDownloadInfo.grandTotal
59
- /* will be emitted on _flush */
60
- ) {
61
- this.nextUpdate = now + 1000;
55
+ beginRangeDownload() {
56
+ this.operationType = OperationKind.DOWNLOAD;
57
+ this.expectedBytes += this.progressDifferentialDownloadInfo.expectedByteCounts[this.index++];
58
+ }
59
+ endRangeDownload() {
60
+ // _flush() will doour final 100%
61
+ if (this.transferred !== this.progressDifferentialDownloadInfo.grandTotal) {
62
+ this.onProgress({
63
+ total: this.progressDifferentialDownloadInfo.grandTotal,
64
+ delta: this.delta,
65
+ transferred: this.transferred,
66
+ percent: (this.transferred / this.progressDifferentialDownloadInfo.grandTotal) * 100,
67
+ bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000)),
68
+ });
69
+ }
70
+ }
71
+ // Called when we are 100% done with the connection/download
72
+ _flush(callback) {
73
+ if (this.cancellationToken.cancelled) {
74
+ callback(new Error("cancelled"));
75
+ return;
76
+ }
62
77
  this.onProgress({
63
- total: this.progressDifferentialDownloadInfo.grandTotal,
64
- delta: this.delta,
65
- transferred: this.transferred,
66
- percent: this.transferred / this.progressDifferentialDownloadInfo.grandTotal * 100,
67
- bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000))
78
+ total: this.progressDifferentialDownloadInfo.grandTotal,
79
+ delta: this.delta,
80
+ transferred: this.transferred,
81
+ percent: 100,
82
+ bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000)),
68
83
  });
69
84
  this.delta = 0;
70
- }
71
-
72
- callback(null, chunk);
73
- }
74
-
75
- beginFileCopy() {
76
- this.operationType = OperationKind.COPY;
77
- }
78
-
79
- beginRangeDownload() {
80
- this.operationType = OperationKind.DOWNLOAD;
81
- this.expectedBytes += this.progressDifferentialDownloadInfo.expectedByteCounts[this.index++];
82
- }
83
-
84
- endRangeDownload() {
85
- // _flush() will doour final 100%
86
- if (this.transferred !== this.progressDifferentialDownloadInfo.grandTotal) {
87
- this.onProgress({
88
- total: this.progressDifferentialDownloadInfo.grandTotal,
89
- delta: this.delta,
90
- transferred: this.transferred,
91
- percent: this.transferred / this.progressDifferentialDownloadInfo.grandTotal * 100,
92
- bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000))
93
- });
85
+ this.transferred = 0;
86
+ callback(null);
94
87
  }
95
- } // Called when we are 100% done with the connection/download
96
-
97
-
98
- _flush(callback) {
99
- if (this.cancellationToken.cancelled) {
100
- callback(new Error("cancelled"));
101
- return;
102
- }
103
-
104
- this.onProgress({
105
- total: this.progressDifferentialDownloadInfo.grandTotal,
106
- delta: this.delta,
107
- transferred: this.transferred,
108
- percent: 100,
109
- bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000))
110
- });
111
- this.delta = 0;
112
- this.transferred = 0;
113
- callback(null);
114
- }
115
-
116
- } exports.ProgressDifferentialDownloadCallbackTransform = ProgressDifferentialDownloadCallbackTransform;
117
- // __ts-babel@6.0.4
88
+ }
89
+ exports.ProgressDifferentialDownloadCallbackTransform = ProgressDifferentialDownloadCallbackTransform;
118
90
  //# sourceMappingURL=ProgressDifferentialDownloadCallbackTransform.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.ts"],"names":[],"mappings":";;;;;;;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAGA,IAAK,aAAL;;AAAA,CAAA,UAAK,aAAL,EAAkB;AAChB,EAAA,aAAA,CAAA,aAAA,CAAA,MAAA,CAAA,GAAA,CAAA,CAAA,GAAA,MAAA;AAAM,EAAA,aAAA,CAAA,aAAA,CAAA,UAAA,CAAA,GAAA,CAAA,CAAA,GAAA,UAAA;AACP,CAFD,EAAK,aAAa,KAAb,aAAa,GAAA,EAAA,CAAlB;;AAiBM,MAAO,6CAAP,SAA6D,mBAA7D,CAAsE;AAU1E,EAAA,WAAA,CAA6B,gCAA7B,EAAkH,iBAAlH,EAAyK,UAAzK,EAAgN;AAC9M;AAD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,KAAK,KAFE;AAGd,MAAA,WAAW,EAAE,KAAK,WAHJ;AAId,MAAA,OAAO,EAAE,GAJK;AAKd,MAAA,cAAc,EAAE,IAAI,CAAC,KAAL,CAAW,KAAK,WAAL,IAAoB,CAAC,IAAI,CAAC,GAAL,KAAa,KAAK,KAAnB,IAA4B,IAAhD,CAAX;AALF,KAAhB;AAOA,SAAK,KAAL,GAAa,CAAb;AACA,SAAK,WAAL,GAAmB,CAAnB;AAGA,IAAA,QAAQ,CAAC,IAAD,CAAR;AACD;;AA1FyE,C","sourcesContent":["import { Transform } from \"stream\"\nimport { CancellationToken } from \"builder-util-runtime\"\n\nenum OperationKind {\n COPY, DOWNLOAD\n}\n\nexport interface ProgressInfo {\n total: number\n delta: number\n transferred: number\n percent: number\n bytesPerSecond: number\n}\n\nexport interface ProgressDifferentialDownloadInfo {\n expectedByteCounts: Array<number>\n grandTotal: number\n}\n\nexport class ProgressDifferentialDownloadCallbackTransform extends Transform {\n private start = Date.now()\n private transferred = 0\n private delta = 0\n private expectedBytes = 0\n private index = 0\n private operationType = OperationKind.COPY\n\n private nextUpdate = this.start + 1000\n\n constructor(private readonly progressDifferentialDownloadInfo: ProgressDifferentialDownloadInfo, private readonly cancellationToken: CancellationToken, private readonly onProgress: (info: ProgressInfo) => any) {\n super()\n }\n\n _transform(chunk: any, encoding: string, callback: any) {\n if (this.cancellationToken.cancelled) {\n callback(new Error(\"cancelled\"), null)\n return\n }\n\n // Don't send progress update when copying from disk\n if (this.operationType == OperationKind.COPY) {\n callback(null, chunk)\n return\n }\n\n this.transferred += chunk.length\n this.delta += chunk.length\n\n const now = Date.now()\n if (now >= this.nextUpdate\n && this.transferred !== this.expectedBytes /* will be emitted by endRangeDownload() */\n && this.transferred !== this.progressDifferentialDownloadInfo.grandTotal /* will be emitted on _flush */) {\n this.nextUpdate = now + 1000\n\n this.onProgress({\n total: this.progressDifferentialDownloadInfo.grandTotal,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.progressDifferentialDownloadInfo.grandTotal) * 100,\n bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000))\n })\n this.delta = 0\n }\n\n callback(null, chunk)\n }\n\n beginFileCopy(): void {\n this.operationType = OperationKind.COPY\n }\n\n beginRangeDownload(): void {\n this.operationType = OperationKind.DOWNLOAD\n\n this.expectedBytes += this.progressDifferentialDownloadInfo.expectedByteCounts[this.index++]\n }\n\n endRangeDownload(): void {\n // _flush() will doour final 100%\n if (this.transferred !== this.progressDifferentialDownloadInfo.grandTotal) {\n this.onProgress({\n total: this.progressDifferentialDownloadInfo.grandTotal,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.progressDifferentialDownloadInfo.grandTotal) * 100,\n bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000))\n })\n }\n }\n\n // Called when we are 100% done with the connection/download\n _flush(callback: any): void {\n if (this.cancellationToken.cancelled) {\n callback(new Error(\"cancelled\"))\n return\n }\n\n this.onProgress({\n total: this.progressDifferentialDownloadInfo.grandTotal,\n delta: this.delta,\n transferred: this.transferred,\n percent: 100,\n bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000))\n })\n this.delta = 0\n this.transferred = 0\n\n\n callback(null)\n }\n}\n"],"sourceRoot":""}
1
+ {"version":3,"file":"ProgressDifferentialDownloadCallbackTransform.js","sourceRoot":"","sources":["../../src/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAGlC,IAAK,aAGJ;AAHD,WAAK,aAAa;IAChB,iDAAI,CAAA;IACJ,yDAAQ,CAAA;AACV,CAAC,EAHI,aAAa,KAAb,aAAa,QAGjB;AAeD,MAAa,6CAA8C,SAAQ,kBAAS;IAU1E,YACmB,gCAAkE,EAClE,iBAAoC,EACpC,UAAuC;QAExD,KAAK,EAAE,CAAA;QAJU,qCAAgC,GAAhC,gCAAgC,CAAkC;QAClE,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC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ACpC,QAAQ,CAAC,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;YAChC,OAAM;SACP;QAED,IAAI,CAAC,UAAU,CAAC;YACd,KAAK,EAAE,IAAI,CAAC,gCAAgC,CAAC,UAAU;YACvD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE,GAAG;YACZ,cAAc,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;SAClF,CAAC,CAAA;QACF,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;QACd,IAAI,CAAC,WAAW,GAAG,CAAC,CAAA;QAEpB,QAAQ,CAAC,IAAI,CAAC,CAAA;IAChB,CAAC;CACF;AAhGD,sGAgGC","sourcesContent":["import { Transform } from \"stream\"\nimport { CancellationToken } from \"builder-util-runtime\"\n\nenum OperationKind {\n COPY,\n DOWNLOAD,\n}\n\nexport interface ProgressInfo {\n total: number\n delta: number\n transferred: number\n percent: number\n bytesPerSecond: number\n}\n\nexport interface ProgressDifferentialDownloadInfo {\n expectedByteCounts: Array<number>\n grandTotal: number\n}\n\nexport class ProgressDifferentialDownloadCallbackTransform extends Transform {\n private start = Date.now()\n private transferred = 0\n private delta = 0\n private expectedBytes = 0\n private index = 0\n private operationType = OperationKind.COPY\n\n private nextUpdate = this.start + 1000\n\n constructor(\n private readonly progressDifferentialDownloadInfo: ProgressDifferentialDownloadInfo,\n private readonly cancellationToken: CancellationToken,\n private readonly onProgress: (info: ProgressInfo) => any\n ) {\n super()\n }\n\n _transform(chunk: any, encoding: string, callback: any) {\n if (this.cancellationToken.cancelled) {\n callback(new Error(\"cancelled\"), null)\n return\n }\n\n // Don't send progress update when copying from disk\n if (this.operationType == OperationKind.COPY) {\n callback(null, chunk)\n return\n }\n\n this.transferred += chunk.length\n this.delta += chunk.length\n\n const now = Date.now()\n if (\n now >= this.nextUpdate &&\n this.transferred !== this.expectedBytes /* will be emitted by endRangeDownload() */ &&\n this.transferred !== this.progressDifferentialDownloadInfo.grandTotal /* will be emitted on _flush */\n ) {\n this.nextUpdate = now + 1000\n\n this.onProgress({\n total: this.progressDifferentialDownloadInfo.grandTotal,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.progressDifferentialDownloadInfo.grandTotal) * 100,\n bytesPerSecond: Math.round(this.transferred / ((now - this.start) / 1000)),\n })\n this.delta = 0\n }\n\n callback(null, chunk)\n }\n\n beginFileCopy(): void {\n this.operationType = OperationKind.COPY\n }\n\n beginRangeDownload(): void {\n this.operationType = OperationKind.DOWNLOAD\n\n this.expectedBytes += this.progressDifferentialDownloadInfo.expectedByteCounts[this.index++]\n }\n\n endRangeDownload(): void {\n // _flush() will doour final 100%\n if (this.transferred !== this.progressDifferentialDownloadInfo.grandTotal) {\n this.onProgress({\n total: this.progressDifferentialDownloadInfo.grandTotal,\n delta: this.delta,\n transferred: this.transferred,\n percent: (this.transferred / this.progressDifferentialDownloadInfo.grandTotal) * 100,\n bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000)),\n })\n }\n }\n\n // Called when we are 100% done with the connection/download\n _flush(callback: any): void {\n if (this.cancellationToken.cancelled) {\n callback(new Error(\"cancelled\"))\n return\n }\n\n this.onProgress({\n total: this.progressDifferentialDownloadInfo.grandTotal,\n delta: this.delta,\n transferred: this.transferred,\n percent: 100,\n bytesPerSecond: Math.round(this.transferred / ((Date.now() - this.start) / 1000)),\n })\n this.delta = 0\n this.transferred = 0\n\n callback(null)\n }\n}\n"]}