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.
- package/LICENSE +22 -0
- package/out/AppAdapter.js +19 -28
- package/out/AppAdapter.js.map +1 -1
- package/out/AppImageUpdater.js +103 -195
- package/out/AppImageUpdater.js.map +1 -1
- package/out/AppUpdater.d.ts +1 -1
- package/out/AppUpdater.js +517 -771
- package/out/AppUpdater.js.map +1 -1
- package/out/BaseUpdater.js +79 -103
- package/out/BaseUpdater.js.map +1 -1
- package/out/DownloadedUpdateHelper.js +150 -223
- package/out/DownloadedUpdateHelper.js.map +1 -1
- package/out/ElectronAppAdapter.js +35 -63
- package/out/ElectronAppAdapter.js.map +1 -1
- package/out/MacUpdater.js +132 -201
- package/out/MacUpdater.js.map +1 -1
- package/out/NoOpLogger.d.ts +6 -0
- package/out/NoOpLogger.js +19 -0
- package/out/NoOpLogger.js.map +1 -0
- package/out/NsisUpdater.js +199 -345
- package/out/NsisUpdater.js.map +1 -1
- package/out/differentialDownloader/DataSplitter.js +180 -252
- package/out/differentialDownloader/DataSplitter.js.map +1 -1
- package/out/differentialDownloader/DifferentialDownloader.d.ts +1 -1
- package/out/differentialDownloader/DifferentialDownloader.js +242 -355
- package/out/differentialDownloader/DifferentialDownloader.js.map +1 -1
- package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js +29 -65
- package/out/differentialDownloader/FileWithEmbeddedBlockMapDifferentialDownloader.js.map +1 -1
- package/out/differentialDownloader/GenericDifferentialDownloader.js +7 -21
- package/out/differentialDownloader/GenericDifferentialDownloader.js.map +1 -1
- package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js +79 -107
- package/out/differentialDownloader/ProgressDifferentialDownloadCallbackTransform.js.map +1 -1
- package/out/differentialDownloader/downloadPlanBuilder.js +99 -123
- package/out/differentialDownloader/downloadPlanBuilder.js.map +1 -1
- package/out/differentialDownloader/multipleRangeDownloader.js +99 -148
- package/out/differentialDownloader/multipleRangeDownloader.js.map +1 -1
- package/out/electronHttpExecutor.js +73 -106
- package/out/electronHttpExecutor.js.map +1 -1
- package/out/event.d.ts +35 -0
- package/out/event.js +39 -0
- package/out/event.js.map +1 -0
- package/out/log.d.ts +11 -0
- package/out/log.js +19 -0
- package/out/log.js.map +1 -0
- package/out/main.d.ts +1 -3
- package/out/main.js +60 -196
- package/out/main.js.map +1 -1
- package/out/providerFactory.js +49 -105
- package/out/providerFactory.js.map +1 -1
- package/out/providers/BintrayProvider.d.ts +2 -2
- package/out/providers/BintrayProvider.js +40 -95
- package/out/providers/BintrayProvider.js.map +1 -1
- package/out/providers/GenericProvider.d.ts +2 -2
- package/out/providers/GenericProvider.js +46 -80
- package/out/providers/GenericProvider.js.map +1 -1
- package/out/providers/GitHubProvider.d.ts +2 -2
- package/out/providers/GitHubProvider.js +122 -201
- package/out/providers/GitHubProvider.js.map +1 -1
- package/out/providers/PrivateGitHubProvider.js +87 -165
- package/out/providers/PrivateGitHubProvider.js.map +1 -1
- package/out/providers/Provider.js +122 -173
- package/out/providers/Provider.js.map +1 -1
- package/out/util.d.ts +5 -0
- package/out/util.js +42 -0
- package/out/util.js.map +1 -0
- package/out/windowsExecutableCodeSignatureVerifier.js +99 -139
- package/out/windowsExecutableCodeSignatureVerifier.js.map +1 -1
- package/package.json +33 -31
|
@@ -1,138 +1,114 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.computeOperations = computeOperations;
|
|
7
|
-
exports.OperationKind = void 0;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeOperations = exports.OperationKind = void 0;
|
|
8
4
|
var OperationKind;
|
|
9
|
-
exports.OperationKind = OperationKind;
|
|
10
|
-
|
|
11
5
|
(function (OperationKind) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})(OperationKind
|
|
15
|
-
|
|
6
|
+
OperationKind[OperationKind["COPY"] = 0] = "COPY";
|
|
7
|
+
OperationKind[OperationKind["DOWNLOAD"] = 1] = "DOWNLOAD";
|
|
8
|
+
})(OperationKind = exports.OperationKind || (exports.OperationKind = {}));
|
|
16
9
|
function computeOperations(oldBlockMap, newBlockMap, logger) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
10
|
+
const nameToOldBlocks = buildBlockFileMap(oldBlockMap.files);
|
|
11
|
+
const nameToNewBlocks = buildBlockFileMap(newBlockMap.files);
|
|
12
|
+
let lastOperation = null;
|
|
13
|
+
// for now only one file is supported in block map
|
|
14
|
+
const blockMapFile = newBlockMap.files[0];
|
|
15
|
+
const operations = [];
|
|
16
|
+
const name = blockMapFile.name;
|
|
17
|
+
const oldEntry = nameToOldBlocks.get(name);
|
|
18
|
+
if (oldEntry == null) {
|
|
19
|
+
// new file (unrealistic case for now, because in any case both blockmap contain the only file named as "file")
|
|
20
|
+
throw new Error(`no file ${name} in old blockmap`);
|
|
21
|
+
}
|
|
22
|
+
const newFile = nameToNewBlocks.get(name);
|
|
23
|
+
let changedBlockCount = 0;
|
|
24
|
+
const { checksumToOffset: checksumToOldOffset, checksumToOldSize } = buildChecksumMap(nameToOldBlocks.get(name), oldEntry.offset, logger);
|
|
25
|
+
let newOffset = blockMapFile.offset;
|
|
26
|
+
for (let i = 0; i < newFile.checksums.length; newOffset += newFile.sizes[i], i++) {
|
|
27
|
+
const blockSize = newFile.sizes[i];
|
|
28
|
+
const checksum = newFile.checksums[i];
|
|
29
|
+
let oldOffset = checksumToOldOffset.get(checksum);
|
|
30
|
+
if (oldOffset != null && checksumToOldSize.get(checksum) !== blockSize) {
|
|
31
|
+
logger.warn(`Checksum ("${checksum}") matches, but size differs (old: ${checksumToOldSize.get(checksum)}, new: ${blockSize})`);
|
|
32
|
+
oldOffset = undefined;
|
|
33
|
+
}
|
|
34
|
+
if (oldOffset === undefined) {
|
|
35
|
+
// download data from new file
|
|
36
|
+
changedBlockCount++;
|
|
37
|
+
if (lastOperation != null && lastOperation.kind === OperationKind.DOWNLOAD && lastOperation.end === newOffset) {
|
|
38
|
+
lastOperation.end += blockSize;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
lastOperation = {
|
|
42
|
+
kind: OperationKind.DOWNLOAD,
|
|
43
|
+
start: newOffset,
|
|
44
|
+
end: newOffset + blockSize,
|
|
45
|
+
// oldBlocks: null,
|
|
46
|
+
};
|
|
47
|
+
validateAndAdd(lastOperation, operations, checksum, i);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// reuse data from old file
|
|
52
|
+
if (lastOperation != null && lastOperation.kind === OperationKind.COPY && lastOperation.end === oldOffset) {
|
|
53
|
+
lastOperation.end += blockSize;
|
|
54
|
+
// lastOperation.oldBlocks!!.push(checksum)
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
lastOperation = {
|
|
58
|
+
kind: OperationKind.COPY,
|
|
59
|
+
start: oldOffset,
|
|
60
|
+
end: oldOffset + blockSize,
|
|
61
|
+
// oldBlocks: [checksum]
|
|
62
|
+
};
|
|
63
|
+
validateAndAdd(lastOperation, operations, checksum, i);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
47
66
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// download data from new file
|
|
51
|
-
changedBlockCount++;
|
|
52
|
-
|
|
53
|
-
if (lastOperation != null && lastOperation.kind === OperationKind.DOWNLOAD && lastOperation.end === newOffset) {
|
|
54
|
-
lastOperation.end += blockSize;
|
|
55
|
-
} else {
|
|
56
|
-
lastOperation = {
|
|
57
|
-
kind: OperationKind.DOWNLOAD,
|
|
58
|
-
start: newOffset,
|
|
59
|
-
end: newOffset + blockSize
|
|
60
|
-
};
|
|
61
|
-
validateAndAdd(lastOperation, operations, checksum, i);
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
// reuse data from old file
|
|
65
|
-
if (lastOperation != null && lastOperation.kind === OperationKind.COPY && lastOperation.end === oldOffset) {
|
|
66
|
-
lastOperation.end += blockSize; // lastOperation.oldBlocks!!.push(checksum)
|
|
67
|
-
} else {
|
|
68
|
-
lastOperation = {
|
|
69
|
-
kind: OperationKind.COPY,
|
|
70
|
-
start: oldOffset,
|
|
71
|
-
end: oldOffset + blockSize
|
|
72
|
-
};
|
|
73
|
-
validateAndAdd(lastOperation, operations, checksum, i);
|
|
74
|
-
}
|
|
67
|
+
if (changedBlockCount > 0) {
|
|
68
|
+
logger.info(`File${blockMapFile.name === "file" ? "" : " " + blockMapFile.name} has ${changedBlockCount} changed blocks`);
|
|
75
69
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (changedBlockCount > 0) {
|
|
79
|
-
logger.info(`File${blockMapFile.name === "file" ? "" : " " + blockMapFile.name} has ${changedBlockCount} changed blocks`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return operations;
|
|
70
|
+
return operations;
|
|
83
71
|
}
|
|
84
|
-
|
|
72
|
+
exports.computeOperations = computeOperations;
|
|
85
73
|
const isValidateOperationRange = process.env.DIFFERENTIAL_DOWNLOAD_PLAN_BUILDER_VALIDATE_RANGES === "true";
|
|
86
|
-
|
|
87
74
|
function validateAndAdd(operation, operations, checksum, index) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
75
|
+
if (isValidateOperationRange && operations.length !== 0) {
|
|
76
|
+
const lastOperation = operations[operations.length - 1];
|
|
77
|
+
if (lastOperation.kind === operation.kind && operation.start < lastOperation.end && operation.start > lastOperation.start) {
|
|
78
|
+
const min = [lastOperation.start, lastOperation.end, operation.start, operation.end].reduce((p, v) => (p < v ? p : v));
|
|
79
|
+
throw new Error(`operation (block index: ${index}, checksum: ${checksum}, kind: ${OperationKind[operation.kind]}) overlaps previous operation (checksum: ${checksum}):\n` +
|
|
80
|
+
`abs: ${lastOperation.start} until ${lastOperation.end} and ${operation.start} until ${operation.end}\n` +
|
|
81
|
+
`rel: ${lastOperation.start - min} until ${lastOperation.end - min} and ${operation.start - min} until ${operation.end - min}`);
|
|
82
|
+
}
|
|
94
83
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
99
|
-
|
|
100
|
-
|
|
84
|
+
operations.push(operation);
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
101
87
|
function buildChecksumMap(file, fileOffset, logger) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
88
|
+
const checksumToOffset = new Map();
|
|
89
|
+
const checksumToSize = new Map();
|
|
90
|
+
let offset = fileOffset;
|
|
91
|
+
for (let i = 0; i < file.checksums.length; i++) {
|
|
92
|
+
const checksum = file.checksums[i];
|
|
93
|
+
const size = file.sizes[i];
|
|
94
|
+
const existing = checksumToSize.get(checksum);
|
|
95
|
+
if (existing === undefined) {
|
|
96
|
+
checksumToOffset.set(checksum, offset);
|
|
97
|
+
checksumToSize.set(checksum, size);
|
|
98
|
+
}
|
|
99
|
+
else if (logger.debug != null) {
|
|
100
|
+
const sizeExplanation = existing === size ? "(same size)" : `(size: ${existing}, this size: ${size})`;
|
|
101
|
+
logger.debug(`${checksum} duplicated in blockmap ${sizeExplanation}, it doesn't lead to broken differential downloader, just corresponding block will be skipped)`);
|
|
102
|
+
}
|
|
103
|
+
offset += size;
|
|
117
104
|
}
|
|
118
|
-
|
|
119
|
-
offset += size;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
checksumToOffset,
|
|
124
|
-
checksumToOldSize: checksumToSize
|
|
125
|
-
};
|
|
105
|
+
return { checksumToOffset, checksumToOldSize: checksumToSize };
|
|
126
106
|
}
|
|
127
|
-
|
|
128
107
|
function buildBlockFileMap(list) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
// __ts-babel@6.0.4
|
|
108
|
+
const result = new Map();
|
|
109
|
+
for (const item of list) {
|
|
110
|
+
result.set(item.name, item);
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
138
114
|
//# sourceMappingURL=downloadPlanBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/differentialDownloader/downloadPlanBuilder.ts"],"names":[],"mappings":";;;;;;;AAGA,IAAY,aAAZ;;;AAAA,CAAA,UAAY,aAAZ,EAAyB;AACvB,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,EAAY,aAAa,6BAAb,aAAa,GAAA,EAAA,CAAzB;;AAgBM,SAAU,iBAAV,CAA4B,WAA5B,EAAmD,WAAnD,EAA0E,MAA1E,EAAwF;AAC5F,QAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC,KAAb,CAAzC;AACA,QAAM,eAAe,GAAG,iBAAiB,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\nimport { Logger } from \"../main\"\n\nexport enum OperationKind {\n COPY, DOWNLOAD\n}\n\nexport interface Operation {\n kind: OperationKind\n\n // inclusive\n start: number\n // exclusive\n end: number\n\n // debug only\n // oldBlocks: Array<string> | null\n}\n\nexport function computeOperations(oldBlockMap: BlockMap, newBlockMap: BlockMap, logger: Logger): Array<Operation> {\n const nameToOldBlocks = buildBlockFileMap(oldBlockMap.files)\n const nameToNewBlocks = buildBlockFileMap(newBlockMap.files)\n\n let lastOperation: Operation | null = null\n\n // for now only one file is supported in block map\n const blockMapFile = newBlockMap.files[0]\n const operations: Array<Operation> = []\n const name = blockMapFile.name\n const oldEntry = nameToOldBlocks.get(name)\n if (oldEntry == null) {\n // new file (unrealistic case for now, because in any case both blockmap contain the only file named as \"file\")\n throw new Error(`no file ${name} in old blockmap`)\n }\n\n const newFile = nameToNewBlocks.get(name)!!\n let changedBlockCount = 0\n\n const {checksumToOffset: checksumToOldOffset, checksumToOldSize} = buildChecksumMap(nameToOldBlocks.get(name)!!, oldEntry.offset, logger)\n\n let newOffset = blockMapFile.offset\n for (let i = 0; i < newFile.checksums.length; newOffset += newFile.sizes[i], i++) {\n const blockSize = newFile.sizes[i]\n const checksum = newFile.checksums[i]\n let oldOffset = checksumToOldOffset.get(checksum)\n if (oldOffset != null && checksumToOldSize.get(checksum) !== blockSize) {\n logger.warn(`Checksum (\"${checksum}\") matches, but size differs (old: ${checksumToOldSize.get(checksum)}, new: ${blockSize})`)\n oldOffset = undefined\n }\n\n if (oldOffset === undefined) {\n // download data from new file\n changedBlockCount++\n\n if (lastOperation != null && lastOperation.kind === OperationKind.DOWNLOAD && lastOperation.end === newOffset) {\n lastOperation.end += blockSize\n }\n else {\n lastOperation = {\n kind: OperationKind.DOWNLOAD,\n start: newOffset,\n end: newOffset + blockSize,\n // oldBlocks: null,\n }\n validateAndAdd(lastOperation, operations, checksum, i)\n }\n }\n else {\n // reuse data from old file\n if (lastOperation != null && lastOperation.kind === OperationKind.COPY && lastOperation.end === oldOffset) {\n lastOperation.end += blockSize\n // lastOperation.oldBlocks!!.push(checksum)\n }\n else {\n lastOperation = {\n kind: OperationKind.COPY,\n start: oldOffset,\n end: oldOffset + blockSize,\n // oldBlocks: [checksum]\n }\n validateAndAdd(lastOperation, operations, checksum, i)\n }\n }\n }\n\n if (changedBlockCount > 0) {\n logger.info(`File${blockMapFile.name === \"file\" ? \"\" : (\" \" + blockMapFile.name)} has ${changedBlockCount} changed blocks`)\n }\n return operations\n}\n\nconst isValidateOperationRange = process.env.DIFFERENTIAL_DOWNLOAD_PLAN_BUILDER_VALIDATE_RANGES === \"true\"\n\nfunction validateAndAdd(operation: Operation, operations: Array<Operation>, checksum: string, index: number): void {\n if (isValidateOperationRange && operations.length !== 0) {\n const lastOperation = operations[operations.length - 1]\n if (lastOperation.kind === operation.kind && operation.start < lastOperation.end && operation.start > lastOperation.start) {\n const min = [lastOperation.start, lastOperation.end, operation.start, operation.end].reduce((p, v) => p < v ? p : v)\n throw new Error(`operation (block index: ${index}, checksum: ${checksum}, kind: ${OperationKind[operation.kind]}) overlaps previous operation (checksum: ${checksum}):\\n` +\n `abs: ${lastOperation.start} until ${lastOperation.end} and ${operation.start} until ${operation.end}\\n` +\n `rel: ${lastOperation.start - min} until ${lastOperation.end - min} and ${operation.start - min} until ${operation.end - min}`\n )\n }\n }\n operations.push(operation)\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction buildChecksumMap(file: BlockMapFile, fileOffset: number, logger: Logger) {\n const checksumToOffset = new Map<string, number>()\n const checksumToSize = new Map<string, number>()\n let offset = fileOffset\n for (let i = 0; i < file.checksums.length; i++) {\n const checksum = file.checksums[i]\n const size = file.sizes[i]\n\n const existing = checksumToSize.get(checksum)\n if (existing === undefined) {\n checksumToOffset.set(checksum, offset)\n checksumToSize.set(checksum, size)\n }\n else if (logger.debug != null) {\n const sizeExplanation = existing === size ? \"(same size)\" : `(size: ${existing}, this size: ${size})`\n logger.debug(`${checksum} duplicated in blockmap ${sizeExplanation}, it doesn't lead to broken differential downloader, just corresponding block will be skipped)`)\n }\n offset += size\n }\n return {checksumToOffset, checksumToOldSize: checksumToSize}\n}\n\nfunction buildBlockFileMap(list: Array<BlockMapFile>): Map<string, BlockMapFile> {\n const result = new Map<string, BlockMapFile>()\n for (const item of list) {\n result.set(item.name, item)\n }\n return result\n}\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"downloadPlanBuilder.js","sourceRoot":"","sources":["../../src/differentialDownloader/downloadPlanBuilder.ts"],"names":[],"mappings":";;;AAGA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,iDAAI,CAAA;IACJ,yDAAQ,CAAA;AACV,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB;AAcD,SAAgB,iBAAiB,CAAC,WAAqB,EAAE,WAAqB,EAAE,MAAc;IAC5F,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAC5D,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAE5D,IAAI,aAAa,GAAqB,IAAI,CAAA;IAE1C,kDAAkD;IAClD,MAAM,YAAY,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACzC,MAAM,UAAU,GAAqB,EAAE,CAAA;IACvC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAA;IAC9B,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC1C,IAAI,QAAQ,IAAI,IAAI,EAAE;QACpB,+GAA+G;QAC/G,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,kBAAkB,CAAC,CAAA;KACnD;IAED,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,CAAE,CAAA;IAC1C,IAAI,iBAAiB,GAAG,CAAC,CAAA;IAEzB,MAAM,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,iBAAiB,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AQ,CAAC,CAAA;QAC7C,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,gBAAgB,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;YACtC,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;SACnC;aAAM,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE;YAC/B,MAAM,eAAe,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,QAAQ,gBAAgB,IAAI,GAAG,CAAA;YACrG,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,2BAA2B,eAAe,gGAAgG,CAAC,CAAA;SACpK;QACD,MAAM,IAAI,IAAI,CAAA;KACf;IACD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,CAAA;AAChE,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAyB;IAClD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAwB,CAAA;IAC9C,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;QACvB,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;KAC5B;IACD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { BlockMap, BlockMapFile } from \"builder-util-runtime/out/blockMapApi\"\nimport { Logger } from \"../main\"\n\nexport enum OperationKind {\n COPY,\n DOWNLOAD,\n}\n\nexport interface Operation {\n kind: OperationKind\n\n // inclusive\n start: number\n // exclusive\n end: number\n\n // debug only\n // oldBlocks: Array<string> | null\n}\n\nexport function computeOperations(oldBlockMap: BlockMap, newBlockMap: BlockMap, logger: Logger): Array<Operation> {\n const nameToOldBlocks = buildBlockFileMap(oldBlockMap.files)\n const nameToNewBlocks = buildBlockFileMap(newBlockMap.files)\n\n let lastOperation: Operation | null = null\n\n // for now only one file is supported in block map\n const blockMapFile = newBlockMap.files[0]\n const operations: Array<Operation> = []\n const name = blockMapFile.name\n const oldEntry = nameToOldBlocks.get(name)\n if (oldEntry == null) {\n // new file (unrealistic case for now, because in any case both blockmap contain the only file named as \"file\")\n throw new Error(`no file ${name} in old blockmap`)\n }\n\n const newFile = nameToNewBlocks.get(name)!\n let changedBlockCount = 0\n\n const { checksumToOffset: checksumToOldOffset, checksumToOldSize } = buildChecksumMap(nameToOldBlocks.get(name)!, oldEntry.offset, logger)\n\n let newOffset = blockMapFile.offset\n for (let i = 0; i < newFile.checksums.length; newOffset += newFile.sizes[i], i++) {\n const blockSize = newFile.sizes[i]\n const checksum = newFile.checksums[i]\n let oldOffset = checksumToOldOffset.get(checksum)\n if (oldOffset != null && checksumToOldSize.get(checksum) !== blockSize) {\n logger.warn(`Checksum (\"${checksum}\") matches, but size differs (old: ${checksumToOldSize.get(checksum)}, new: ${blockSize})`)\n oldOffset = undefined\n }\n\n if (oldOffset === undefined) {\n // download data from new file\n changedBlockCount++\n\n if (lastOperation != null && lastOperation.kind === OperationKind.DOWNLOAD && lastOperation.end === newOffset) {\n lastOperation.end += blockSize\n } else {\n lastOperation = {\n kind: OperationKind.DOWNLOAD,\n start: newOffset,\n end: newOffset + blockSize,\n // oldBlocks: null,\n }\n validateAndAdd(lastOperation, operations, checksum, i)\n }\n } else {\n // reuse data from old file\n if (lastOperation != null && lastOperation.kind === OperationKind.COPY && lastOperation.end === oldOffset) {\n lastOperation.end += blockSize\n // lastOperation.oldBlocks!!.push(checksum)\n } else {\n lastOperation = {\n kind: OperationKind.COPY,\n start: oldOffset,\n end: oldOffset + blockSize,\n // oldBlocks: [checksum]\n }\n validateAndAdd(lastOperation, operations, checksum, i)\n }\n }\n }\n\n if (changedBlockCount > 0) {\n logger.info(`File${blockMapFile.name === \"file\" ? \"\" : \" \" + blockMapFile.name} has ${changedBlockCount} changed blocks`)\n }\n return operations\n}\n\nconst isValidateOperationRange = process.env.DIFFERENTIAL_DOWNLOAD_PLAN_BUILDER_VALIDATE_RANGES === \"true\"\n\nfunction validateAndAdd(operation: Operation, operations: Array<Operation>, checksum: string, index: number): void {\n if (isValidateOperationRange && operations.length !== 0) {\n const lastOperation = operations[operations.length - 1]\n if (lastOperation.kind === operation.kind && operation.start < lastOperation.end && operation.start > lastOperation.start) {\n const min = [lastOperation.start, lastOperation.end, operation.start, operation.end].reduce((p, v) => (p < v ? p : v))\n throw new Error(\n `operation (block index: ${index}, checksum: ${checksum}, kind: ${OperationKind[operation.kind]}) overlaps previous operation (checksum: ${checksum}):\\n` +\n `abs: ${lastOperation.start} until ${lastOperation.end} and ${operation.start} until ${operation.end}\\n` +\n `rel: ${lastOperation.start - min} until ${lastOperation.end - min} and ${operation.start - min} until ${operation.end - min}`\n )\n }\n }\n operations.push(operation)\n}\n\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nfunction buildChecksumMap(file: BlockMapFile, fileOffset: number, logger: Logger) {\n const checksumToOffset = new Map<string, number>()\n const checksumToSize = new Map<string, number>()\n let offset = fileOffset\n for (let i = 0; i < file.checksums.length; i++) {\n const checksum = file.checksums[i]\n const size = file.sizes[i]\n\n const existing = checksumToSize.get(checksum)\n if (existing === undefined) {\n checksumToOffset.set(checksum, offset)\n checksumToSize.set(checksum, size)\n } else if (logger.debug != null) {\n const sizeExplanation = existing === size ? \"(same size)\" : `(size: ${existing}, this size: ${size})`\n logger.debug(`${checksum} duplicated in blockmap ${sizeExplanation}, it doesn't lead to broken differential downloader, just corresponding block will be skipped)`)\n }\n offset += size\n }\n return { checksumToOffset, checksumToOldSize: checksumToSize }\n}\n\nfunction buildBlockFileMap(list: Array<BlockMapFile>): Map<string, BlockMapFile> {\n const result = new Map<string, BlockMapFile>()\n for (const item of list) {\n result.set(item.name, item)\n }\n return result\n}\n"]}
|
|
@@ -1,161 +1,112 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.checkIsRangesSupported = checkIsRangesSupported;
|
|
8
|
-
|
|
9
|
-
function _builderUtilRuntime() {
|
|
10
|
-
const data = require("builder-util-runtime");
|
|
11
|
-
|
|
12
|
-
_builderUtilRuntime = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return data;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function _DataSplitter() {
|
|
20
|
-
const data = require("./DataSplitter");
|
|
21
|
-
|
|
22
|
-
_DataSplitter = function () {
|
|
23
|
-
return data;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function _downloadPlanBuilder() {
|
|
30
|
-
const data = require("./downloadPlanBuilder");
|
|
31
|
-
|
|
32
|
-
_downloadPlanBuilder = function () {
|
|
33
|
-
return data;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
return data;
|
|
37
|
-
}
|
|
38
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIsRangesSupported = exports.executeTasksUsingMultipleRangeRequests = void 0;
|
|
4
|
+
const builder_util_runtime_1 = require("builder-util-runtime");
|
|
5
|
+
const DataSplitter_1 = require("./DataSplitter");
|
|
6
|
+
const downloadPlanBuilder_1 = require("./downloadPlanBuilder");
|
|
39
7
|
function executeTasksUsingMultipleRangeRequests(differentialDownloader, tasks, out, oldFileFd, reject) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return w;
|
|
8
|
+
const w = (taskOffset) => {
|
|
9
|
+
if (taskOffset >= tasks.length) {
|
|
10
|
+
if (differentialDownloader.fileMetadataBuffer != null) {
|
|
11
|
+
out.write(differentialDownloader.fileMetadataBuffer);
|
|
12
|
+
}
|
|
13
|
+
out.end();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const nextOffset = taskOffset + 1000;
|
|
17
|
+
doExecuteTasks(differentialDownloader, {
|
|
18
|
+
tasks,
|
|
19
|
+
start: taskOffset,
|
|
20
|
+
end: Math.min(tasks.length, nextOffset),
|
|
21
|
+
oldFileFd,
|
|
22
|
+
}, out, () => w(nextOffset), reject);
|
|
23
|
+
};
|
|
24
|
+
return w;
|
|
60
25
|
}
|
|
61
|
-
|
|
26
|
+
exports.executeTasksUsingMultipleRangeRequests = executeTasksUsingMultipleRangeRequests;
|
|
62
27
|
function doExecuteTasks(differentialDownloader, options, out, resolve, reject) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
partIndexToLength.push(task.end - task.start);
|
|
28
|
+
let ranges = "bytes=";
|
|
29
|
+
let partCount = 0;
|
|
30
|
+
const partIndexToTaskIndex = new Map();
|
|
31
|
+
const partIndexToLength = [];
|
|
32
|
+
for (let i = options.start; i < options.end; i++) {
|
|
33
|
+
const task = options.tasks[i];
|
|
34
|
+
if (task.kind === downloadPlanBuilder_1.OperationKind.DOWNLOAD) {
|
|
35
|
+
ranges += `${task.start}-${task.end - 1}, `;
|
|
36
|
+
partIndexToTaskIndex.set(partCount, i);
|
|
37
|
+
partCount++;
|
|
38
|
+
partIndexToLength.push(task.end - task.start);
|
|
39
|
+
}
|
|
76
40
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
41
|
+
if (partCount <= 1) {
|
|
42
|
+
// the only remote range - copy
|
|
43
|
+
const w = (index) => {
|
|
44
|
+
if (index >= options.end) {
|
|
45
|
+
resolve();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const task = options.tasks[index++];
|
|
49
|
+
if (task.kind === downloadPlanBuilder_1.OperationKind.COPY) {
|
|
50
|
+
DataSplitter_1.copyData(task, out, options.oldFileFd, reject, () => w(index));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const requestOptions = differentialDownloader.createRequestOptions();
|
|
54
|
+
requestOptions.headers.Range = `bytes=${task.start}-${task.end - 1}`;
|
|
55
|
+
const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
|
|
56
|
+
if (!checkIsRangesSupported(response, reject)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
response.pipe(out, {
|
|
60
|
+
end: false,
|
|
61
|
+
});
|
|
62
|
+
response.once("end", () => w(index));
|
|
63
|
+
});
|
|
64
|
+
differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
|
|
65
|
+
request.end();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
w(options.start);
|
|
84
69
|
return;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
}
|
|
71
|
+
const requestOptions = differentialDownloader.createRequestOptions();
|
|
72
|
+
requestOptions.headers.Range = ranges.substring(0, ranges.length - 2);
|
|
73
|
+
const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
|
|
74
|
+
if (!checkIsRangesSupported(response, reject)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const contentType = builder_util_runtime_1.safeGetHeader(response, "content-type");
|
|
78
|
+
const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType);
|
|
79
|
+
if (m == null) {
|
|
80
|
+
reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`));
|
|
96
81
|
return;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
82
|
+
}
|
|
83
|
+
const dicer = new DataSplitter_1.DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve);
|
|
84
|
+
dicer.on("error", reject);
|
|
85
|
+
response.pipe(dicer);
|
|
86
|
+
response.on("end", () => {
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
request.abort();
|
|
89
|
+
reject(new Error("Response ends without calling any handlers"));
|
|
90
|
+
}, 10000);
|
|
103
91
|
});
|
|
104
|
-
differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
|
|
105
|
-
request.end();
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
w(options.start);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const requestOptions = differentialDownloader.createRequestOptions();
|
|
114
|
-
requestOptions.headers.Range = ranges.substring(0, ranges.length - 2);
|
|
115
|
-
const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {
|
|
116
|
-
if (!checkIsRangesSupported(response, reject)) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const contentType = (0, _builderUtilRuntime().safeGetHeader)(response, "content-type");
|
|
121
|
-
const m = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i.exec(contentType);
|
|
122
|
-
|
|
123
|
-
if (m == null) {
|
|
124
|
-
reject(new Error(`Content-Type "multipart/byteranges" is expected, but got "${contentType}"`));
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const dicer = new (_DataSplitter().DataSplitter)(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve);
|
|
129
|
-
dicer.on("error", reject);
|
|
130
|
-
response.pipe(dicer);
|
|
131
|
-
response.on('end', () => {
|
|
132
|
-
setTimeout(() => {
|
|
133
|
-
request.abort();
|
|
134
|
-
reject(new Error("Response ends without calling any handlers"));
|
|
135
|
-
}, 10000);
|
|
136
92
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
request.end();
|
|
93
|
+
differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject);
|
|
94
|
+
request.end();
|
|
140
95
|
}
|
|
141
|
-
|
|
142
96
|
function checkIsRangesSupported(response, reject) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return false;
|
|
97
|
+
// Electron net handles redirects automatically, our NodeJS test server doesn't use redirects - so, we don't check 3xx codes.
|
|
98
|
+
if (response.statusCode >= 400) {
|
|
99
|
+
reject(builder_util_runtime_1.createHttpError(response));
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (response.statusCode !== 206) {
|
|
103
|
+
const acceptRanges = builder_util_runtime_1.safeGetHeader(response, "accept-ranges");
|
|
104
|
+
if (acceptRanges == null || acceptRanges === "none") {
|
|
105
|
+
reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`));
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
155
108
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
// __ts-babel@6.0.4
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
exports.checkIsRangesSupported = checkIsRangesSupported;
|
|
161
112
|
//# sourceMappingURL=multipleRangeDownloader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/differentialDownloader/multipleRangeDownloader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multipleRangeDownloader.js","sourceRoot":"","sources":["../../src/differentialDownloader/multipleRangeDownloader.ts"],"names":[],"mappings":";;;AAAA,+DAAqE;AAGrE,iDAAyE;AAEzE,+DAAgE;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U,CAAC,GAAG,EAAE;gBACd,OAAO,CAAC,KAAK,EAAE,CAAA;gBACf,MAAM,CAAC,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC,CAAA;YACjE,CAAC,EAAE,KAAK,CAAC,CAAA;QACX,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,sBAAsB,CAAC,YAAY,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC/E,OAAO,CAAC,GAAG,EAAE,CAAA;AACf,CAAC;AAED,SAAgB,sBAAsB,CAAC,QAAyB,EAAE,MAA8B;IAC9F,6HAA6H;IAC7H,IAAI,QAAQ,CAAC,UAAW,IAAI,GAAG,EAAE;QAC/B,MAAM,CAAC,sCAAe,CAAC,QAAQ,CAAC,CAAC,CAAA;QACjC,OAAO,KAAK,CAAA;KACb;IAED,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE;QAC/B,MAAM,YAAY,GAAG,oCAAa,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAA;QAC7D,IAAI,YAAY,IAAI,IAAI,IAAI,YAAY,KAAK,MAAM,EAAE;YACnD,MAAM,CAAC,IAAI,KAAK,CAAC,uDAAuD,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;YAChG,OAAO,KAAK,CAAA;SACb;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAfD,wDAeC","sourcesContent":["import { createHttpError, safeGetHeader } from \"builder-util-runtime\"\nimport { IncomingMessage } from \"http\"\nimport { Writable } from \"stream\"\nimport { copyData, DataSplitter, PartListDataTask } from \"./DataSplitter\"\nimport { DifferentialDownloader } from \"./DifferentialDownloader\"\nimport { Operation, OperationKind } from \"./downloadPlanBuilder\"\n\nexport function executeTasksUsingMultipleRangeRequests(\n differentialDownloader: DifferentialDownloader,\n tasks: Array<Operation>,\n out: Writable,\n oldFileFd: number,\n reject: (error: Error) => void\n): (taskOffset: number) => void {\n const w = (taskOffset: number): void => {\n if (taskOffset >= tasks.length) {\n if (differentialDownloader.fileMetadataBuffer != null) {\n out.write(differentialDownloader.fileMetadataBuffer)\n }\n out.end()\n return\n }\n\n const nextOffset = taskOffset + 1000\n doExecuteTasks(\n differentialDownloader,\n {\n tasks,\n start: taskOffset,\n end: Math.min(tasks.length, nextOffset),\n oldFileFd,\n },\n out,\n () => w(nextOffset),\n reject\n )\n }\n return w\n}\n\nfunction doExecuteTasks(differentialDownloader: DifferentialDownloader, options: PartListDataTask, out: Writable, resolve: () => void, reject: (error: Error) => void): void {\n let ranges = \"bytes=\"\n let partCount = 0\n const partIndexToTaskIndex = new Map<number, number>()\n const partIndexToLength: Array<number> = []\n for (let i = options.start; i < options.end; i++) {\n const task = options.tasks[i]\n if (task.kind === OperationKind.DOWNLOAD) {\n ranges += `${task.start}-${task.end - 1}, `\n partIndexToTaskIndex.set(partCount, i)\n partCount++\n partIndexToLength.push(task.end - task.start)\n }\n }\n\n if (partCount <= 1) {\n // the only remote range - copy\n const w = (index: number): void => {\n if (index >= options.end) {\n resolve()\n return\n }\n\n const task = options.tasks[index++]\n\n if (task.kind === OperationKind.COPY) {\n copyData(task, out, options.oldFileFd, reject, () => w(index))\n } else {\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = `bytes=${task.start}-${task.end - 1}`\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n response.pipe(out, {\n end: false,\n })\n response.once(\"end\", () => w(index))\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n }\n }\n\n w(options.start)\n return\n }\n\n const requestOptions = differentialDownloader.createRequestOptions()\n requestOptions.headers!.Range = ranges.substring(0, ranges.length - 2)\n const request = differentialDownloader.httpExecutor.createRequest(requestOptions, response => {\n if (!checkIsRangesSupported(response, reject)) {\n return\n }\n\n const contentType = safeGetHeader(response, \"content-type\")\n const m = /^multipart\\/.+?(?:; boundary=(?:(?:\"(.+)\")|(?:([^\\s]+))))$/i.exec(contentType)\n if (m == null) {\n reject(new Error(`Content-Type \"multipart/byteranges\" is expected, but got \"${contentType}\"`))\n return\n }\n\n const dicer = new DataSplitter(out, options, partIndexToTaskIndex, m[1] || m[2], partIndexToLength, resolve)\n dicer.on(\"error\", reject)\n response.pipe(dicer)\n\n response.on(\"end\", () => {\n setTimeout(() => {\n request.abort()\n reject(new Error(\"Response ends without calling any handlers\"))\n }, 10000)\n })\n })\n differentialDownloader.httpExecutor.addErrorAndTimeoutHandlers(request, reject)\n request.end()\n}\n\nexport function checkIsRangesSupported(response: IncomingMessage, reject: (error: Error) => void): boolean {\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 return false\n }\n\n if (response.statusCode !== 206) {\n const acceptRanges = safeGetHeader(response, \"accept-ranges\")\n if (acceptRanges == null || acceptRanges === \"none\") {\n reject(new Error(`Server doesn't support Accept-Ranges (response code ${response.statusCode})`))\n return false\n }\n }\n return true\n}\n"]}
|