UNPKG

3.45 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.createBlockmap = exports.appendBlockmap = exports.configureDifferentialAwareArchiveOptions = exports.createNsisWebDifferentialUpdateInfo = exports.BLOCK_MAP_FILE_SUFFIX = void 0;
4const builder_util_1 = require("builder-util");
5const path = require("path");
6const appBuilder_1 = require("../util/appBuilder");
7exports.BLOCK_MAP_FILE_SUFFIX = ".blockmap";
8function createNsisWebDifferentialUpdateInfo(artifactPath, packageFiles) {
9 if (packageFiles == null) {
10 return null;
11 }
12 const keys = Object.keys(packageFiles);
13 if (keys.length <= 0) {
14 return null;
15 }
16 const packages = {};
17 for (const arch of keys) {
18 const packageFileInfo = packageFiles[arch];
19 const file = path.basename(packageFileInfo.path);
20 packages[arch] = {
21 ...packageFileInfo,
22 path: file,
23 // https://github.com/electron-userland/electron-builder/issues/2583
24 file,
25 };
26 }
27 return { packages };
28}
29exports.createNsisWebDifferentialUpdateInfo = createNsisWebDifferentialUpdateInfo;
30function configureDifferentialAwareArchiveOptions(archiveOptions) {
31 /*
32 * dict size 64 MB: Full: 33,744.88 KB, To download: 17,630.3 KB (52%)
33 * dict size 16 MB: Full: 33,936.84 KB, To download: 16,175.9 KB (48%)
34 * dict size 8 MB: Full: 34,187.59 KB, To download: 8,229.9 KB (24%)
35 * dict size 4 MB: Full: 34,628.73 KB, To download: 3,782.97 KB (11%)
36
37 as we can see, if file changed in one place, all block is invalidated (and update size approximately equals to dict size)
38
39 1 MB is used:
40
41 1MB:
42
43 2018/01/11 11:54:41:0045 File has 59 changed blocks
44 2018/01/11 11:54:41:0050 Full: 71,588.59 KB, To download: 1,243.39 KB (2%)
45
46 4MB:
47
48 2018/01/11 11:31:43:0440 Full: 70,303.55 KB, To download: 4,843.27 KB (7%)
49 2018/01/11 11:31:43:0435 File has 234 changed blocks
50
51 */
52 archiveOptions.dictSize = 1;
53 // solid compression leads to a lot of changed blocks
54 archiveOptions.solid = false;
55 // do not allow to change compression level to avoid different packages
56 archiveOptions.compression = "normal";
57 return archiveOptions;
58}
59exports.configureDifferentialAwareArchiveOptions = configureDifferentialAwareArchiveOptions;
60async function appendBlockmap(file) {
61 builder_util_1.log.info({ file: builder_util_1.log.filePath(file) }, "building embedded block map");
62 return await (0, appBuilder_1.executeAppBuilderAsJson)(["blockmap", "--input", file, "--compression", "deflate"]);
63}
64exports.appendBlockmap = appendBlockmap;
65async function createBlockmap(file, target, packager, safeArtifactName) {
66 const blockMapFile = `${file}${exports.BLOCK_MAP_FILE_SUFFIX}`;
67 builder_util_1.log.info({ blockMapFile: builder_util_1.log.filePath(blockMapFile) }, "building block map");
68 const updateInfo = await (0, appBuilder_1.executeAppBuilderAsJson)(["blockmap", "--input", file, "--output", blockMapFile]);
69 await packager.info.callArtifactBuildCompleted({
70 file: blockMapFile,
71 safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${exports.BLOCK_MAP_FILE_SUFFIX}`,
72 target,
73 arch: null,
74 packager,
75 updateInfo,
76 });
77 return updateInfo;
78}
79exports.createBlockmap = createBlockmap;
80//# sourceMappingURL=differentialUpdateInfoBuilder.js.map
\No newline at end of file