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,374 +1,261 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.DifferentialDownloader = void 0;
7
-
8
- function _builderUtilRuntime() {
9
- const data = require("builder-util-runtime");
10
-
11
- _builderUtilRuntime = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _fsExtra() {
19
- const data = require("fs-extra");
20
-
21
- _fsExtra = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- var _fs = require("fs");
29
-
30
- function _DataSplitter() {
31
- const data = require("./DataSplitter");
32
-
33
- _DataSplitter = function () {
34
- return data;
35
- };
36
-
37
- return data;
38
- }
39
-
40
- function _url() {
41
- const data = require("url");
42
-
43
- _url = function () {
44
- return data;
45
- };
46
-
47
- return data;
48
- }
49
-
50
- function _downloadPlanBuilder() {
51
- const data = require("./downloadPlanBuilder");
52
-
53
- _downloadPlanBuilder = function () {
54
- return data;
55
- };
56
-
57
- return data;
58
- }
59
-
60
- function _multipleRangeDownloader() {
61
- const data = require("./multipleRangeDownloader");
62
-
63
- _multipleRangeDownloader = function () {
64
- return data;
65
- };
66
-
67
- return data;
68
- }
69
-
70
- function _ProgressDifferentialDownloadCallbackTransform() {
71
- const data = require("./ProgressDifferentialDownloadCallbackTransform");
72
-
73
- _ProgressDifferentialDownloadCallbackTransform = function () {
74
- return data;
75
- };
76
-
77
- return data;
78
- }
79
-
4
+ const builder_util_runtime_1 = require("builder-util-runtime");
5
+ const fs_extra_1 = require("fs-extra");
6
+ const fs_1 = require("fs");
7
+ const DataSplitter_1 = require("./DataSplitter");
8
+ const url_1 = require("url");
9
+ const downloadPlanBuilder_1 = require("./downloadPlanBuilder");
10
+ const multipleRangeDownloader_1 = require("./multipleRangeDownloader");
11
+ const ProgressDifferentialDownloadCallbackTransform_1 = require("./ProgressDifferentialDownloadCallbackTransform");
80
12
  class DifferentialDownloader {
81
- // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
82
- constructor(blockAwareFileInfo, httpExecutor, options) {
83
- this.blockAwareFileInfo = blockAwareFileInfo;
84
- this.httpExecutor = httpExecutor;
85
- this.options = options;
86
- this.fileMetadataBuffer = null;
87
- this.logger = options.logger;
88
- }
89
-
90
- createRequestOptions() {
91
- const result = {
92
- headers: { ...this.options.requestHeaders,
93
- accept: "*/*"
94
- }
95
- };
96
- (0, _builderUtilRuntime().configureRequestUrl)(this.options.newUrl, result); // user-agent, cache-control and other common options
97
-
98
- (0, _builderUtilRuntime().configureRequestOptions)(result);
99
- return result;
100
- }
101
-
102
- doDownload(oldBlockMap, newBlockMap) {
103
- // we don't check other metadata like compressionMethod - generic check that it is make sense to differentially update is suitable for it
104
- if (oldBlockMap.version !== newBlockMap.version) {
105
- throw new Error(`version is different (${oldBlockMap.version} - ${newBlockMap.version}), full download is required`);
106
- }
107
-
108
- const logger = this.logger;
109
- const operations = (0, _downloadPlanBuilder().computeOperations)(oldBlockMap, newBlockMap, logger);
110
-
111
- if (logger.debug != null) {
112
- logger.debug(JSON.stringify(operations, null, 2));
13
+ // noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
14
+ constructor(blockAwareFileInfo, httpExecutor, options) {
15
+ this.blockAwareFileInfo = blockAwareFileInfo;
16
+ this.httpExecutor = httpExecutor;
17
+ this.options = options;
18
+ this.fileMetadataBuffer = null;
19
+ this.logger = options.logger;
113
20
  }
114
-
115
- let downloadSize = 0;
116
- let copySize = 0;
117
-
118
- for (const operation of operations) {
119
- const length = operation.end - operation.start;
120
-
121
- if (operation.kind === _downloadPlanBuilder().OperationKind.DOWNLOAD) {
122
- downloadSize += length;
123
- } else {
124
- copySize += length;
125
- }
126
- }
127
-
128
- const newSize = this.blockAwareFileInfo.size;
129
-
130
- if (downloadSize + copySize + (this.fileMetadataBuffer == null ? 0 : this.fileMetadataBuffer.length) !== newSize) {
131
- throw new Error(`Internal error, size mismatch: downloadSize: ${downloadSize}, copySize: ${copySize}, newSize: ${newSize}`);
132
- }
133
-
134
- logger.info(`Full: ${formatBytes(newSize)}, To download: ${formatBytes(downloadSize)} (${Math.round(downloadSize / (newSize / 100))}%)`);
135
- return this.downloadFile(operations);
136
- }
137
-
138
- downloadFile(tasks) {
139
- const fdList = [];
140
-
141
- const closeFiles = () => {
142
- return Promise.all(fdList.map(openedFile => {
143
- return (0, _fsExtra().close)(openedFile.descriptor).catch(e => {
144
- this.logger.error(`cannot close file "${openedFile.path}": ${e}`);
145
- });
146
- }));
147
- };
148
-
149
- return this.doDownloadFile(tasks, fdList).then(closeFiles).catch(e => {
150
- // then must be after catch here (since then always throws error)
151
- return closeFiles().catch(closeFilesError => {
152
- // closeFiles never throw error, but just to be sure
153
- try {
154
- this.logger.error(`cannot close files: ${closeFilesError}`);
155
- } catch (errorOnLog) {
156
- try {
157
- console.error(errorOnLog);
158
- } catch (ignored) {// ok, give up and ignore error
159
- }
160
- }
161
-
162
- throw e;
163
- }).then(() => {
164
- throw e;
165
- });
166
- });
167
- }
168
-
169
- async doDownloadFile(tasks, fdList) {
170
- const oldFileFd = await (0, _fsExtra().open)(this.options.oldFile, "r");
171
- fdList.push({
172
- descriptor: oldFileFd,
173
- path: this.options.oldFile
174
- });
175
- const newFileFd = await (0, _fsExtra().open)(this.options.newFile, "w");
176
- fdList.push({
177
- descriptor: newFileFd,
178
- path: this.options.newFile
179
- });
180
- const fileOut = (0, _fs.createWriteStream)(this.options.newFile, {
181
- fd: newFileFd
182
- });
183
- await new Promise((resolve, reject) => {
184
- const streams = []; // Create our download info transformer if we have one
185
-
186
- let downloadInfoTransform = undefined;
187
-
188
- if (!this.options.isUseMultipleRangeRequest && this.options.onProgress) {
189
- // TODO: Does not support multiple ranges (someone feel free to PR this!)
190
- const expectedByteCounts = [];
191
- let grandTotalBytes = 0;
192
-
193
- for (const task of tasks) {
194
- if (task.kind === _downloadPlanBuilder().OperationKind.DOWNLOAD) {
195
- expectedByteCounts.push(task.end - task.start);
196
- grandTotalBytes += task.end - task.start;
197
- }
198
- }
199
-
200
- const progressDifferentialDownloadInfo = {
201
- expectedByteCounts: expectedByteCounts,
202
- grandTotal: grandTotalBytes
21
+ createRequestOptions() {
22
+ const result = {
23
+ headers: {
24
+ ...this.options.requestHeaders,
25
+ accept: "*/*",
26
+ },
203
27
  };
204
- downloadInfoTransform = new (_ProgressDifferentialDownloadCallbackTransform().ProgressDifferentialDownloadCallbackTransform)(progressDifferentialDownloadInfo, this.options.cancellationToken, this.options.onProgress);
205
- streams.push(downloadInfoTransform);
206
- }
207
-
208
- const digestTransform = new (_builderUtilRuntime().DigestTransform)(this.blockAwareFileInfo.sha512); // to simply debug, do manual validation to allow file to be fully written
209
-
210
- digestTransform.isValidateOnEnd = false;
211
- streams.push(digestTransform); // noinspection JSArrowFunctionCanBeReplacedWithShorthand
212
-
213
- fileOut.on("finish", () => {
214
- fileOut.close(() => {
215
- // remove from fd list because closed successfully
216
- fdList.splice(1, 1);
217
-
218
- try {
219
- digestTransform.validate();
220
- } catch (e) {
221
- reject(e);
222
- return;
223
- }
224
-
225
- resolve(undefined);
226
- });
227
- });
228
- streams.push(fileOut);
229
- let lastStream = null;
230
-
231
- for (const stream of streams) {
232
- stream.on("error", reject);
233
-
234
- if (lastStream == null) {
235
- lastStream = stream;
236
- } else {
237
- lastStream = lastStream.pipe(stream);
28
+ builder_util_runtime_1.configureRequestUrl(this.options.newUrl, result);
29
+ // user-agent, cache-control and other common options
30
+ builder_util_runtime_1.configureRequestOptions(result);
31
+ return result;
32
+ }
33
+ doDownload(oldBlockMap, newBlockMap) {
34
+ // we don't check other metadata like compressionMethod - generic check that it is make sense to differentially update is suitable for it
35
+ if (oldBlockMap.version !== newBlockMap.version) {
36
+ throw new Error(`version is different (${oldBlockMap.version} - ${newBlockMap.version}), full download is required`);
238
37
  }
239
- }
240
-
241
- const firstStream = streams[0];
242
- let w;
243
-
244
- if (this.options.isUseMultipleRangeRequest) {
245
- w = (0, _multipleRangeDownloader().executeTasksUsingMultipleRangeRequests)(this, tasks, firstStream, oldFileFd, reject);
246
- w(0);
247
- return;
248
- }
249
-
250
- let downloadOperationCount = 0;
251
- let actualUrl = null;
252
- this.logger.info(`Differential download: ${this.options.newUrl}`);
253
- const requestOptions = this.createRequestOptions();
254
- requestOptions.redirect = "manual";
255
-
256
- w = index => {
257
- if (index >= tasks.length) {
258
- if (this.fileMetadataBuffer != null) {
259
- firstStream.write(this.fileMetadataBuffer);
260
- }
261
-
262
- firstStream.end();
263
- return;
38
+ const logger = this.logger;
39
+ const operations = downloadPlanBuilder_1.computeOperations(oldBlockMap, newBlockMap, logger);
40
+ if (logger.debug != null) {
41
+ logger.debug(JSON.stringify(operations, null, 2));
264
42
  }
265
-
266
- const operation = tasks[index++];
267
-
268
- if (operation.kind === _downloadPlanBuilder().OperationKind.COPY) {
269
- // We are copying, let's not send status updates to the UI
270
- if (downloadInfoTransform) {
271
- downloadInfoTransform.beginFileCopy();
272
- }
273
-
274
- (0, _DataSplitter().copyData)(operation, firstStream, oldFileFd, reject, () => w(index));
275
- return;
43
+ let downloadSize = 0;
44
+ let copySize = 0;
45
+ for (const operation of operations) {
46
+ const length = operation.end - operation.start;
47
+ if (operation.kind === downloadPlanBuilder_1.OperationKind.DOWNLOAD) {
48
+ downloadSize += length;
49
+ }
50
+ else {
51
+ copySize += length;
52
+ }
276
53
  }
277
-
278
- const range = `bytes=${operation.start}-${operation.end - 1}`;
279
- requestOptions.headers.range = range;
280
- const debug = this.logger.debug;
281
-
282
- if (debug != null) {
283
- debug(`download range: ${range}`);
284
- } // We are starting to download
285
-
286
-
287
- if (downloadInfoTransform) {
288
- downloadInfoTransform.beginRangeDownload();
54
+ const newSize = this.blockAwareFileInfo.size;
55
+ if (downloadSize + copySize + (this.fileMetadataBuffer == null ? 0 : this.fileMetadataBuffer.length) !== newSize) {
56
+ throw new Error(`Internal error, size mismatch: downloadSize: ${downloadSize}, copySize: ${copySize}, newSize: ${newSize}`);
289
57
  }
290
-
291
- const request = this.httpExecutor.createRequest(requestOptions, response => {
292
- // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
293
- if (response.statusCode >= 400) {
294
- reject((0, _builderUtilRuntime().createHttpError)(response));
295
- }
296
-
297
- response.pipe(firstStream, {
298
- end: false
299
- });
300
- response.once("end", () => {
301
- // Pass on that we are downloading a segment
302
- if (downloadInfoTransform) {
303
- downloadInfoTransform.endRangeDownload();
58
+ logger.info(`Full: ${formatBytes(newSize)}, To download: ${formatBytes(downloadSize)} (${Math.round(downloadSize / (newSize / 100))}%)`);
59
+ return this.downloadFile(operations);
60
+ }
61
+ downloadFile(tasks) {
62
+ const fdList = [];
63
+ const closeFiles = () => {
64
+ return Promise.all(fdList.map(openedFile => {
65
+ return fs_extra_1.close(openedFile.descriptor).catch(e => {
66
+ this.logger.error(`cannot close file "${openedFile.path}": ${e}`);
67
+ });
68
+ }));
69
+ };
70
+ return this.doDownloadFile(tasks, fdList)
71
+ .then(closeFiles)
72
+ .catch(e => {
73
+ // then must be after catch here (since then always throws error)
74
+ return closeFiles()
75
+ .catch(closeFilesError => {
76
+ // closeFiles never throw error, but just to be sure
77
+ try {
78
+ this.logger.error(`cannot close files: ${closeFilesError}`);
79
+ }
80
+ catch (errorOnLog) {
81
+ try {
82
+ console.error(errorOnLog);
83
+ }
84
+ catch (ignored) {
85
+ // ok, give up and ignore error
86
+ }
87
+ }
88
+ throw e;
89
+ })
90
+ .then(() => {
91
+ throw e;
92
+ });
93
+ });
94
+ }
95
+ async doDownloadFile(tasks, fdList) {
96
+ const oldFileFd = await fs_extra_1.open(this.options.oldFile, "r");
97
+ fdList.push({ descriptor: oldFileFd, path: this.options.oldFile });
98
+ const newFileFd = await fs_extra_1.open(this.options.newFile, "w");
99
+ fdList.push({ descriptor: newFileFd, path: this.options.newFile });
100
+ const fileOut = fs_1.createWriteStream(this.options.newFile, { fd: newFileFd });
101
+ await new Promise((resolve, reject) => {
102
+ const streams = [];
103
+ // Create our download info transformer if we have one
104
+ let downloadInfoTransform = undefined;
105
+ if (!this.options.isUseMultipleRangeRequest && this.options.onProgress) {
106
+ // TODO: Does not support multiple ranges (someone feel free to PR this!)
107
+ const expectedByteCounts = [];
108
+ let grandTotalBytes = 0;
109
+ for (const task of tasks) {
110
+ if (task.kind === downloadPlanBuilder_1.OperationKind.DOWNLOAD) {
111
+ expectedByteCounts.push(task.end - task.start);
112
+ grandTotalBytes += task.end - task.start;
113
+ }
114
+ }
115
+ const progressDifferentialDownloadInfo = {
116
+ expectedByteCounts: expectedByteCounts,
117
+ grandTotal: grandTotalBytes,
118
+ };
119
+ downloadInfoTransform = new ProgressDifferentialDownloadCallbackTransform_1.ProgressDifferentialDownloadCallbackTransform(progressDifferentialDownloadInfo, this.options.cancellationToken, this.options.onProgress);
120
+ streams.push(downloadInfoTransform);
304
121
  }
305
-
306
- if (++downloadOperationCount === 100) {
307
- downloadOperationCount = 0;
308
- setTimeout(() => w(index), 1000);
309
- } else {
310
- w(index);
122
+ const digestTransform = new builder_util_runtime_1.DigestTransform(this.blockAwareFileInfo.sha512);
123
+ // to simply debug, do manual validation to allow file to be fully written
124
+ digestTransform.isValidateOnEnd = false;
125
+ streams.push(digestTransform);
126
+ // noinspection JSArrowFunctionCanBeReplacedWithShorthand
127
+ fileOut.on("finish", () => {
128
+ ;
129
+ fileOut.close(() => {
130
+ // remove from fd list because closed successfully
131
+ fdList.splice(1, 1);
132
+ try {
133
+ digestTransform.validate();
134
+ }
135
+ catch (e) {
136
+ reject(e);
137
+ return;
138
+ }
139
+ resolve(undefined);
140
+ });
141
+ });
142
+ streams.push(fileOut);
143
+ let lastStream = null;
144
+ for (const stream of streams) {
145
+ stream.on("error", reject);
146
+ if (lastStream == null) {
147
+ lastStream = stream;
148
+ }
149
+ else {
150
+ lastStream = lastStream.pipe(stream);
151
+ }
311
152
  }
312
- });
313
- });
314
- request.on("redirect", (statusCode, method, redirectUrl) => {
315
- this.logger.info(`Redirect to ${removeQuery(redirectUrl)}`);
316
- actualUrl = redirectUrl;
317
- (0, _builderUtilRuntime().configureRequestUrl)(new (_url().URL)(actualUrl), requestOptions);
318
- request.followRedirect();
153
+ const firstStream = streams[0];
154
+ let w;
155
+ if (this.options.isUseMultipleRangeRequest) {
156
+ w = multipleRangeDownloader_1.executeTasksUsingMultipleRangeRequests(this, tasks, firstStream, oldFileFd, reject);
157
+ w(0);
158
+ return;
159
+ }
160
+ let downloadOperationCount = 0;
161
+ let actualUrl = null;
162
+ this.logger.info(`Differential download: ${this.options.newUrl}`);
163
+ const requestOptions = this.createRequestOptions();
164
+ requestOptions.redirect = "manual";
165
+ w = (index) => {
166
+ var _a, _b;
167
+ if (index >= tasks.length) {
168
+ if (this.fileMetadataBuffer != null) {
169
+ firstStream.write(this.fileMetadataBuffer);
170
+ }
171
+ firstStream.end();
172
+ return;
173
+ }
174
+ const operation = tasks[index++];
175
+ if (operation.kind === downloadPlanBuilder_1.OperationKind.COPY) {
176
+ // We are copying, let's not send status updates to the UI
177
+ if (downloadInfoTransform) {
178
+ downloadInfoTransform.beginFileCopy();
179
+ }
180
+ DataSplitter_1.copyData(operation, firstStream, oldFileFd, reject, () => w(index));
181
+ return;
182
+ }
183
+ const range = `bytes=${operation.start}-${operation.end - 1}`;
184
+ requestOptions.headers.range = range;
185
+ (_b = (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, `download range: ${range}`);
186
+ // We are starting to download
187
+ if (downloadInfoTransform) {
188
+ downloadInfoTransform.beginRangeDownload();
189
+ }
190
+ const request = this.httpExecutor.createRequest(requestOptions, response => {
191
+ // Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
192
+ if (response.statusCode >= 400) {
193
+ reject(builder_util_runtime_1.createHttpError(response));
194
+ }
195
+ response.pipe(firstStream, {
196
+ end: false,
197
+ });
198
+ response.once("end", () => {
199
+ // Pass on that we are downloading a segment
200
+ if (downloadInfoTransform) {
201
+ downloadInfoTransform.endRangeDownload();
202
+ }
203
+ if (++downloadOperationCount === 100) {
204
+ downloadOperationCount = 0;
205
+ setTimeout(() => w(index), 1000);
206
+ }
207
+ else {
208
+ w(index);
209
+ }
210
+ });
211
+ });
212
+ request.on("redirect", (statusCode, method, redirectUrl) => {
213
+ this.logger.info(`Redirect to ${removeQuery(redirectUrl)}`);
214
+ actualUrl = redirectUrl;
215
+ builder_util_runtime_1.configureRequestUrl(new url_1.URL(actualUrl), requestOptions);
216
+ request.followRedirect();
217
+ });
218
+ this.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
219
+ request.end();
220
+ };
221
+ w(0);
319
222
  });
320
- this.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
321
- request.end();
322
- };
323
-
324
- w(0);
325
- });
326
- }
327
-
328
- async readRemoteBytes(start, endInclusive) {
329
- const buffer = Buffer.allocUnsafe(endInclusive + 1 - start);
330
- const requestOptions = this.createRequestOptions();
331
- requestOptions.headers.range = `bytes=${start}-${endInclusive}`;
332
- let position = 0;
333
- await this.request(requestOptions, chunk => {
334
- chunk.copy(buffer, position);
335
- position += chunk.length;
336
- });
337
-
338
- if (position !== buffer.length) {
339
- throw new Error(`Received data length ${position} is not equal to expected ${buffer.length}`);
340
223
  }
341
-
342
- return buffer;
343
- }
344
-
345
- request(requestOptions, dataHandler) {
346
- return new Promise((resolve, reject) => {
347
- const request = this.httpExecutor.createRequest(requestOptions, response => {
348
- if (!(0, _multipleRangeDownloader().checkIsRangesSupported)(response, reject)) {
349
- return;
224
+ async readRemoteBytes(start, endInclusive) {
225
+ const buffer = Buffer.allocUnsafe(endInclusive + 1 - start);
226
+ const requestOptions = this.createRequestOptions();
227
+ requestOptions.headers.range = `bytes=${start}-${endInclusive}`;
228
+ let position = 0;
229
+ await this.request(requestOptions, chunk => {
230
+ chunk.copy(buffer, position);
231
+ position += chunk.length;
232
+ });
233
+ if (position !== buffer.length) {
234
+ throw new Error(`Received data length ${position} is not equal to expected ${buffer.length}`);
350
235
  }
351
-
352
- response.on("data", dataHandler);
353
- response.on("end", () => resolve());
354
- });
355
- this.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
356
- request.end();
357
- });
358
- }
359
-
236
+ return buffer;
237
+ }
238
+ request(requestOptions, dataHandler) {
239
+ return new Promise((resolve, reject) => {
240
+ const request = this.httpExecutor.createRequest(requestOptions, response => {
241
+ if (!multipleRangeDownloader_1.checkIsRangesSupported(response, reject)) {
242
+ return;
243
+ }
244
+ response.on("data", dataHandler);
245
+ response.on("end", () => resolve());
246
+ });
247
+ this.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
248
+ request.end();
249
+ });
250
+ }
360
251
  }
361
-
362
252
  exports.DifferentialDownloader = DifferentialDownloader;
363
-
364
253
  function formatBytes(value, symbol = " KB") {
365
- return new Intl.NumberFormat("en").format((value / 1024).toFixed(2)) + symbol;
366
- } // safety
367
-
368
-
254
+ return new Intl.NumberFormat("en").format((value / 1024).toFixed(2)) + symbol;
255
+ }
256
+ // safety
369
257
  function removeQuery(url) {
370
- const index = url.indexOf("?");
371
- return index < 0 ? url : url.substring(0, index);
372
- }
373
- // __ts-babel@6.0.4
258
+ const index = url.indexOf("?");
259
+ return index < 0 ? url : url.substring(0, index);
260
+ }
374
261
  //# sourceMappingURL=DifferentialDownloader.js.map