differentialUpdateInfoBuilder.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.createBlockmap = exports.appendBlockmap = exports.configureDifferentialAwareArchiveOptions = exports.createNsisWebDifferentialUpdateInfo = exports.BLOCK_MAP_FILE_SUFFIX = void 0;
  4. const builder_util_1 = require("builder-util");
  5. const path = require("path");
  6. const appBuilder_1 = require("../util/appBuilder");
  7. exports.BLOCK_MAP_FILE_SUFFIX = ".blockmap";
  8. function 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. }
  29. exports.createNsisWebDifferentialUpdateInfo = createNsisWebDifferentialUpdateInfo;
  30. function 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. as we can see, if file changed in one place, all block is invalidated (and update size approximately equals to dict size)
  37. 1 MB is used:
  38. 1MB:
  39. 2018/01/11 11:54:41:0045 File has 59 changed blocks
  40. 2018/01/11 11:54:41:0050 Full: 71,588.59 KB, To download: 1,243.39 KB (2%)
  41. 4MB:
  42. 2018/01/11 11:31:43:0440 Full: 70,303.55 KB, To download: 4,843.27 KB (7%)
  43. 2018/01/11 11:31:43:0435 File has 234 changed blocks
  44. */
  45. archiveOptions.dictSize = 1;
  46. // solid compression leads to a lot of changed blocks
  47. archiveOptions.solid = false;
  48. // do not allow to change compression level to avoid different packages
  49. archiveOptions.compression = "normal";
  50. return archiveOptions;
  51. }
  52. exports.configureDifferentialAwareArchiveOptions = configureDifferentialAwareArchiveOptions;
  53. async function appendBlockmap(file) {
  54. builder_util_1.log.info({ file: builder_util_1.log.filePath(file) }, "building embedded block map");
  55. return await (0, appBuilder_1.executeAppBuilderAsJson)(["blockmap", "--input", file, "--compression", "deflate"]);
  56. }
  57. exports.appendBlockmap = appendBlockmap;
  58. async function createBlockmap(file, target, packager, safeArtifactName) {
  59. const blockMapFile = `${file}${exports.BLOCK_MAP_FILE_SUFFIX}`;
  60. builder_util_1.log.info({ blockMapFile: builder_util_1.log.filePath(blockMapFile) }, "building block map");
  61. const updateInfo = await (0, appBuilder_1.executeAppBuilderAsJson)(["blockmap", "--input", file, "--output", blockMapFile]);
  62. await packager.info.callArtifactBuildCompleted({
  63. file: blockMapFile,
  64. safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${exports.BLOCK_MAP_FILE_SUFFIX}`,
  65. target,
  66. arch: null,
  67. packager,
  68. updateInfo,
  69. });
  70. return updateInfo;
  71. }
  72. exports.createBlockmap = createBlockmap;
  73. //# sourceMappingURL=differentialUpdateInfoBuilder.js.map