app-builder-lib 27.0.0-alpha.13 → 27.0.0-alpha.14
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/dist/configuration.d.ts +47 -1
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js.map +1 -1
- package/dist/options/PlatformSpecificBuildOptions.d.ts +4 -1
- package/dist/options/PlatformSpecificBuildOptions.d.ts.map +1 -1
- package/dist/options/PlatformSpecificBuildOptions.js.map +1 -1
- package/dist/packager.d.ts +6 -0
- package/dist/packager.d.ts.map +1 -1
- package/dist/packager.js +14 -3
- package/dist/packager.js.map +1 -1
- package/dist/publish/updateInfoBuilder.d.ts.map +1 -1
- package/dist/publish/updateInfoBuilder.js +7 -5
- package/dist/publish/updateInfoBuilder.js.map +1 -1
- package/dist/targets/blockmap/blockmap.d.ts +30 -0
- package/dist/targets/blockmap/blockmap.d.ts.map +1 -1
- package/dist/targets/blockmap/blockmap.js +99 -31
- package/dist/targets/blockmap/blockmap.js.map +1 -1
- package/dist/targets/blockmap/blockmapV3.d.ts +36 -0
- package/dist/targets/blockmap/blockmapV3.d.ts.map +1 -0
- package/dist/targets/blockmap/blockmapV3.js +41 -0
- package/dist/targets/blockmap/blockmapV3.js.map +1 -0
- package/dist/targets/blockmap/verbatimRange.d.ts +6 -0
- package/dist/targets/blockmap/verbatimRange.d.ts.map +1 -1
- package/dist/targets/blockmap/verbatimRange.js +11 -0
- package/dist/targets/blockmap/verbatimRange.js.map +1 -1
- package/dist/targets/differentialUpdateInfoBuilder.d.ts +92 -4
- package/dist/targets/differentialUpdateInfoBuilder.d.ts.map +1 -1
- package/dist/targets/differentialUpdateInfoBuilder.js +266 -10
- package/dist/targets/differentialUpdateInfoBuilder.js.map +1 -1
- package/dist/targets/linux/FpmTarget.d.ts.map +1 -1
- package/dist/targets/linux/FpmTarget.js +15 -1
- package/dist/targets/linux/FpmTarget.js.map +1 -1
- package/dist/targets/targetFactory.d.ts +1 -1
- package/dist/targets/targetFactory.d.ts.map +1 -1
- package/dist/targets/targetFactory.js +22 -0
- package/dist/targets/targetFactory.js.map +1 -1
- package/dist/targets/win/MsiTarget.d.ts +7 -0
- package/dist/targets/win/MsiTarget.d.ts.map +1 -1
- package/dist/targets/win/MsiTarget.js +140 -21
- package/dist/targets/win/MsiTarget.js.map +1 -1
- package/dist/targets/win/nsis/NsisTarget.d.ts.map +1 -1
- package/dist/targets/win/nsis/NsisTarget.js +14 -6
- package/dist/targets/win/nsis/NsisTarget.js.map +1 -1
- package/dist/toolsets/appimage.d.ts +3 -0
- package/dist/toolsets/appimage.d.ts.map +1 -1
- package/dist/toolsets/appimage.js +4 -1
- package/dist/toolsets/appimage.js.map +1 -1
- package/dist/toolsets/wix.d.ts +44 -0
- package/dist/toolsets/wix.d.ts.map +1 -0
- package/dist/toolsets/wix.js +91 -0
- package/dist/toolsets/wix.js.map +1 -0
- package/dist/util/electronUpdaterCompatibility.d.ts +43 -0
- package/dist/util/electronUpdaterCompatibility.d.ts.map +1 -0
- package/dist/util/electronUpdaterCompatibility.js +53 -0
- package/dist/util/electronUpdaterCompatibility.js.map +1 -0
- package/dist/util/packageMetadata.js +115 -51
- package/dist/util/packageMetadata.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +8 -8
- package/scheme.json +45 -6
- package/templates/msi/template.xml +5 -5
- package/templates/msiWrapped/template.xml +1 -1
- package/templates/nsis/assistedInstaller.nsh +32 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verbatimRange.js","sourceRoot":"","sources":["../../../src/targets/blockmap/verbatimRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAExC,yGAAyG;AACz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U,GAAG,YAAY,EAAE,CAAC;oBACvC,oCAAoC;oBACpC,OAAO,IAAI,CAAA;gBACb,CAAC;gBACD,IAAI,CAAC,MAAM,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;oBACvE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;gBACrC,CAAC;gBACD,UAAU,GAAG,KAAK,GAAG,CAAC,CAAA;YACxB,CAAC;YAED,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;YACxD,wEAAwE;YACxE,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;YAC/D,YAAY,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,CAAA;QAC3C,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,cAAc,CAAC,KAAK,EAAE,CAAA;IAC9B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { open, stat } from \"fs/promises\"\n\n/** Bytes of the needle used as the cheap scan probe; a full hash comparison confirms every probe hit. */\nconst PROBE_SIZE = 64 * 1024\n/** Haystack read granularity. Peak memory ≈ READ_CHUNK_SIZE + PROBE_SIZE, independent of file sizes. */\nconst READ_CHUNK_SIZE = 1024 * 1024\n\nexport interface VerbatimRange {\n offset: number\n size: number\n}\n\nasync function hashRange(file: string, start: number, size: number): Promise<string> {\n const hash = createHash(\"sha256\")\n await new Promise<void>((resolve, reject) => {\n createReadStream(file, { start, end: start + size - 1 })\n .on(\"data\", chunk => hash.update(chunk))\n .on(\"end\", resolve)\n .on(\"error\", reject)\n })\n return hash.digest(\"hex\")\n}\n\n/**\n * A needle prepared for `findPreparedVerbatimRange`: its scan probe and full hash, computed once so a\n * needle searched for several times (e.g. resumed past an earlier occurrence) is read only once.\n */\nexport interface VerbatimNeedle {\n readonly file: string\n readonly size: number\n /** sha256 of the whole needle; also what identifies byte-identical needles. */\n readonly hash: string\n /** the first `min(PROBE_SIZE, size)` bytes */\n readonly probe: Buffer\n}\n\n/**\n * Reads what `findPreparedVerbatimRange` needs to know about `needleFile`.\n * @throws when the needle is empty — an empty range is meaningless as a blockmap region.\n */\nexport async function prepareVerbatimNeedle(needleFile: string): Promise<VerbatimNeedle> {\n const size = (await stat(needleFile)).size\n if (size === 0) {\n throw new Error(`Cannot locate an empty file (${needleFile}) inside another file`)\n }\n const probeSize = Math.min(PROBE_SIZE, size)\n const probe = Buffer.allocUnsafe(probeSize)\n const needleHandle = await open(needleFile, \"r\")\n try {\n const { bytesRead } = await needleHandle.read(probe, 0, probeSize, 0)\n if (bytesRead !== probeSize) {\n throw new Error(`Short read of ${needleFile}: expected ${probeSize} bytes, got ${bytesRead}`)\n }\n } finally {\n await needleHandle.close()\n }\n return { file: needleFile, size, hash: await hashRange(needleFile, 0, size), probe }\n}\n\n/**\n * Finds the first byte range of `haystackFile` whose contents are exactly the contents of `needleFile`\n * (e.g. the location of an archive member stored with `Copy` inside an installer that embeds the archive).\n *\n * Streams the haystack in `READ_CHUNK_SIZE` reads (never loads it whole), scanning for the first\n * `min(PROBE_SIZE, needle size)` bytes of the needle — with a `probe.length - 1` byte overlap between\n * reads so a probe straddling a chunk boundary is still seen — and confirms each probe hit by hashing the\n * candidate haystack range against the needle's hash. False-positive probe hits are skipped and the scan\n * continues; the first confirmed match at or after `startOffset` is returned. Passing the end of an\n * earlier match as `startOffset` finds the next occurrence, which is how identical members (e.g. the\n * same asar packaged for several archs) are each given their own range.\n *\n * Reads the needle on every call; a caller searching for the same needle repeatedly should prepare it\n * once with `prepareVerbatimNeedle` and use `findPreparedVerbatimRange`.\n *\n * @returns the confirmed range, or `null` when the needle does not occur verbatim at or after\n * `startOffset` (including when it is larger than the haystack).\n * @throws when the needle is empty — an empty range is meaningless as a blockmap region.\n */\nexport async function findVerbatimRange(haystackFile: string, needleFile: string, startOffset = 0): Promise<VerbatimRange | null> {\n return findPreparedVerbatimRange(haystackFile, await prepareVerbatimNeedle(needleFile), startOffset)\n}\n\n/** `findVerbatimRange` for a needle prepared with `prepareVerbatimNeedle`. */\nexport async function findPreparedVerbatimRange(haystackFile: string, needle: VerbatimNeedle, startOffset = 0): Promise<VerbatimRange | null> {\n if (!Number.isSafeInteger(startOffset) || startOffset < 0) {\n throw new Error(`startOffset must be a non-negative integer, got ${String(startOffset)}`)\n }\n const { size: needleSize, probe, hash: needleHash } = needle\n const probeSize = probe.length\n const haystackSize = (await stat(haystackFile)).size\n if (startOffset + needleSize > haystackSize) {\n return null\n }\n\n const haystackHandle = await open(haystackFile, \"r\")\n try {\n const readBuffer = Buffer.allocUnsafe(READ_CHUNK_SIZE)\n // `carry` holds the last `probe.length - 1` bytes of the previous window so a probe occurrence that\n // straddles two reads is found; a probe can never fit entirely inside the carry, so no hit is reported twice.\n let carry: Buffer = Buffer.alloc(0)\n // Absolute haystack offset of window[0].\n let windowOffset = startOffset\n let readPosition = startOffset\n while (readPosition < haystackSize) {\n const { bytesRead } = await haystackHandle.read(readBuffer, 0, READ_CHUNK_SIZE, readPosition)\n if (bytesRead === 0) {\n break\n }\n readPosition += bytesRead\n const window = carry.length === 0 ? readBuffer.subarray(0, bytesRead) : Buffer.concat([carry, readBuffer.subarray(0, bytesRead)])\n\n let searchFrom = 0\n while (searchFrom <= window.length - probeSize) {\n const index = window.indexOf(probe, searchFrom)\n if (index === -1) {\n break\n }\n const offset = windowOffset + index\n if (offset + needleSize > haystackSize) {\n // no later candidate can fit either\n return null\n }\n if ((await hashRange(haystackFile, offset, needleSize)) === needleHash) {\n return { offset, size: needleSize }\n }\n searchFrom = index + 1\n }\n\n const carrySize = Math.min(probeSize - 1, window.length)\n // copy: `window` may alias `readBuffer`, which the next read overwrites\n carry = Buffer.from(window.subarray(window.length - carrySize))\n windowOffset += window.length - carrySize\n }\n } finally {\n await haystackHandle.close()\n }\n return null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verbatimRange.js","sourceRoot":"","sources":["../../../src/targets/blockmap/verbatimRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAExC,yGAAyG;AACzG,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,CAAA;AAC5B,wGAAwG;AACxG,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAA;AAOnC,KAAK,UAAU,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,IAAY;IAChE,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAA;IACjC,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,gBAAgB,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;aACrD,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACvC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;aAClB,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACxB,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAeD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,UAAkB;IAC5D,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAA;IAC1C,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;QACf,MAAM,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S,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;YACxD,wEAAwE;YACxE,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;YAC/D,YAAY,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,CAAA;QAC3C,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,cAAc,CAAC,KAAK,EAAE,CAAA;IAC9B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { createHash } from \"crypto\"\nimport { createReadStream } from \"fs\"\nimport { open, stat } from \"fs/promises\"\n\n/** Bytes of the needle used as the cheap scan probe; a full hash comparison confirms every probe hit. */\nconst PROBE_SIZE = 64 * 1024\n/** Haystack read granularity. Peak memory ≈ READ_CHUNK_SIZE + PROBE_SIZE, independent of file sizes. */\nconst READ_CHUNK_SIZE = 1024 * 1024\n\nexport interface VerbatimRange {\n offset: number\n size: number\n}\n\nasync function hashRange(file: string, start: number, size: number): Promise<string> {\n const hash = createHash(\"sha256\")\n await new Promise<void>((resolve, reject) => {\n createReadStream(file, { start, end: start + size - 1 })\n .on(\"data\", chunk => hash.update(chunk))\n .on(\"end\", resolve)\n .on(\"error\", reject)\n })\n return hash.digest(\"hex\")\n}\n\n/**\n * A needle prepared for `findPreparedVerbatimRange`: its scan probe and full hash, computed once so a\n * needle searched for several times (e.g. resumed past an earlier occurrence) is read only once.\n */\nexport interface VerbatimNeedle {\n readonly file: string\n readonly size: number\n /** sha256 of the whole needle; also what identifies byte-identical needles. */\n readonly hash: string\n /** the first `min(PROBE_SIZE, size)` bytes */\n readonly probe: Buffer\n}\n\n/**\n * Reads what `findPreparedVerbatimRange` needs to know about `needleFile`.\n * @throws when the needle is empty — an empty range is meaningless as a blockmap region.\n */\nexport async function prepareVerbatimNeedle(needleFile: string): Promise<VerbatimNeedle> {\n const size = (await stat(needleFile)).size\n if (size === 0) {\n throw new Error(`Cannot locate an empty file (${needleFile}) inside another file`)\n }\n const probeSize = Math.min(PROBE_SIZE, size)\n const probe = Buffer.allocUnsafe(probeSize)\n const needleHandle = await open(needleFile, \"r\")\n try {\n const { bytesRead } = await needleHandle.read(probe, 0, probeSize, 0)\n if (bytesRead !== probeSize) {\n throw new Error(`Short read of ${needleFile}: expected ${probeSize} bytes, got ${bytesRead}`)\n }\n } finally {\n await needleHandle.close()\n }\n return { file: needleFile, size, hash: await hashRange(needleFile, 0, size), probe }\n}\n\n/**\n * Finds the first byte range of `haystackFile` whose contents are exactly the contents of `needleFile`\n * (e.g. the location of an archive member stored with `Copy` inside an installer that embeds the archive).\n *\n * Streams the haystack in `READ_CHUNK_SIZE` reads (never loads it whole), scanning for the first\n * `min(PROBE_SIZE, needle size)` bytes of the needle — with a `probe.length - 1` byte overlap between\n * reads so a probe straddling a chunk boundary is still seen — and confirms each probe hit by hashing the\n * candidate haystack range against the needle's hash. False-positive probe hits are skipped and the scan\n * continues; the first confirmed match at or after `startOffset` is returned. Passing the end of an\n * earlier match as `startOffset` finds the next occurrence, which is how identical members (e.g. the\n * same asar packaged for several archs) are each given their own range.\n *\n * Reads the needle on every call; a caller searching for the same needle repeatedly should prepare it\n * once with `prepareVerbatimNeedle` and use `findPreparedVerbatimRange`.\n *\n * @returns the confirmed range, or `null` when the needle does not occur verbatim at or after\n * `startOffset` (including when it is larger than the haystack).\n * @throws when the needle is empty — an empty range is meaningless as a blockmap region.\n */\nexport async function findVerbatimRange(haystackFile: string, needleFile: string, startOffset = 0): Promise<VerbatimRange | null> {\n return findPreparedVerbatimRange(haystackFile, await prepareVerbatimNeedle(needleFile), startOffset)\n}\n\n/**\n * A needle made of in-memory bytes (e.g. the 32-byte signature header of a 7z archive), for\n * `findPreparedVerbatimRange`; `label` only names the needle in messages.\n * @throws when `bytes` is empty.\n */\nexport function prepareVerbatimNeedleFromBuffer(bytes: Buffer, label: string): VerbatimNeedle {\n if (bytes.length === 0) {\n throw new Error(`Cannot locate empty bytes (${label}) inside another file`)\n }\n return { file: label, size: bytes.length, hash: createHash(\"sha256\").update(bytes).digest(\"hex\"), probe: bytes.subarray(0, Math.min(PROBE_SIZE, bytes.length)) }\n}\n\n/** `findVerbatimRange` for a needle prepared with `prepareVerbatimNeedle`. */\nexport async function findPreparedVerbatimRange(haystackFile: string, needle: VerbatimNeedle, startOffset = 0): Promise<VerbatimRange | null> {\n if (!Number.isSafeInteger(startOffset) || startOffset < 0) {\n throw new Error(`startOffset must be a non-negative integer, got ${String(startOffset)}`)\n }\n const { size: needleSize, probe, hash: needleHash } = needle\n const probeSize = probe.length\n const haystackSize = (await stat(haystackFile)).size\n if (startOffset + needleSize > haystackSize) {\n return null\n }\n\n const haystackHandle = await open(haystackFile, \"r\")\n try {\n const readBuffer = Buffer.allocUnsafe(READ_CHUNK_SIZE)\n // `carry` holds the last `probe.length - 1` bytes of the previous window so a probe occurrence that\n // straddles two reads is found; a probe can never fit entirely inside the carry, so no hit is reported twice.\n let carry: Buffer = Buffer.alloc(0)\n // Absolute haystack offset of window[0].\n let windowOffset = startOffset\n let readPosition = startOffset\n while (readPosition < haystackSize) {\n const { bytesRead } = await haystackHandle.read(readBuffer, 0, READ_CHUNK_SIZE, readPosition)\n if (bytesRead === 0) {\n break\n }\n readPosition += bytesRead\n const window = carry.length === 0 ? readBuffer.subarray(0, bytesRead) : Buffer.concat([carry, readBuffer.subarray(0, bytesRead)])\n\n let searchFrom = 0\n while (searchFrom <= window.length - probeSize) {\n const index = window.indexOf(probe, searchFrom)\n if (index === -1) {\n break\n }\n const offset = windowOffset + index\n if (offset + needleSize > haystackSize) {\n // no later candidate can fit either\n return null\n }\n if ((await hashRange(haystackFile, offset, needleSize)) === needleHash) {\n return { offset, size: needleSize }\n }\n searchFrom = index + 1\n }\n\n const carrySize = Math.min(probeSize - 1, window.length)\n // copy: `window` may alias `readBuffer`, which the next read overwrites\n carry = Buffer.from(window.subarray(window.length - carrySize))\n windowOffset += window.length - carrySize\n }\n } finally {\n await haystackHandle.close()\n }\n return null\n}\n"]}
|
|
@@ -5,6 +5,27 @@ import { PlatformPackager } from "../platformPackager.js";
|
|
|
5
5
|
import { ArchiveOptions } from "./archive.js";
|
|
6
6
|
import { BlockMapRegion, BuildBlockMapOptions, ChunkerParams } from "./blockmap/blockmap.js";
|
|
7
7
|
export declare const BLOCK_MAP_FILE_SUFFIX = ".blockmap";
|
|
8
|
+
/**
|
|
9
|
+
* The `.blockmap` formats electron-builder writes (the `blockmap` option), named after the format version they carry: `"v2"`
|
|
10
|
+
* is the gzipped JSON map (`"version": "2"`), `"v3"` the binary range-fetchable map (`EBB3` magic).
|
|
11
|
+
*/
|
|
12
|
+
export type BlockMapFormat = "v2" | "v3";
|
|
13
|
+
/** The binary format: the default when `electronUpdaterCompatibility` allows it. */
|
|
14
|
+
export declare const BINARY_BLOCK_MAP_FORMAT: BlockMapFormat;
|
|
15
|
+
/** The newest format electron-builder writes, what `blockmap: "latest"` selects when `electronUpdaterCompatibility` allows it. */
|
|
16
|
+
export declare const LATEST_BLOCK_MAP_FORMAT: BlockMapFormat;
|
|
17
|
+
/**
|
|
18
|
+
* The format of the `.blockmap` files of a build. The map is read by the updater already installed in the users' apps, which
|
|
19
|
+
* `electronUpdaterCompatibility` describes, so:
|
|
20
|
+
*
|
|
21
|
+
* - unset: the binary format when the range allows only electron-updater 7 and later, else the JSON format (with a warning);
|
|
22
|
+
* - `"latest"`: the newest format the range allows (today the same; unlike unset, it follows future formats);
|
|
23
|
+
* - `"v2"`: the JSON format;
|
|
24
|
+
* - `"v3"`: the binary format, which fails the build when the range includes electron-updater versions that cannot read it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveBlockMapFormat(value: unknown, electronUpdaterCompatibility: string): BlockMapFormat;
|
|
27
|
+
/** The format of the `.blockmap` files `packager` writes. */
|
|
28
|
+
export declare function getBlockMapFormat(packager: PlatformPackager<any>): BlockMapFormat;
|
|
8
29
|
/**
|
|
9
30
|
* Chunker parameters for a stored (`Copy`) archive member — e.g. `resources/app.asar` when
|
|
10
31
|
* `nsis.differentialPackage` is `"store-asar"` — whose bytes sit verbatim in the artifact. Such a member
|
|
@@ -17,6 +38,44 @@ export declare const BLOCK_MAP_FILE_SUFFIX = ".blockmap";
|
|
|
17
38
|
* in full on every update) grows faster than the block savings. `avg` must stay a power of two.
|
|
18
39
|
*/
|
|
19
40
|
export declare const STORED_MEMBER_CHUNKER: ChunkerParams;
|
|
41
|
+
/**
|
|
42
|
+
* `STORED_MEMBER_CHUNKER` counterpart for the `blockmap: "v3"` format (the v3 map of `blockMapV3.ts`). A v3 map costs
|
|
43
|
+
* ~10 B per block in the file but an updater fetches only the super-groups, groups and records that
|
|
44
|
+
* changed, so the v2 trade-off (a finer chunker inflating a map that is re-downloaded in full) no longer
|
|
45
|
+
* applies and the stored member can be chunked at 512 B / 1 KiB / 2 KiB: a one-line change then costs
|
|
46
|
+
* one or two small blocks plus a few KB of map. `max` must fit a v3 record's 16-bit block size.
|
|
47
|
+
*/
|
|
48
|
+
export declare const STORED_MEMBER_CHUNKER_V3: ChunkerParams;
|
|
49
|
+
/**
|
|
50
|
+
* Chunker of the 7z archive header region (`locateArchiveHeaderRegions`). The header of a differential
|
|
51
|
+
* package is stored uncompressed (`configureDifferentialAwareArchiveOptions`) and is a few hundred bytes
|
|
52
|
+
* to a few KB: file names, sizes and CRCs. Between two releases only the CRCs and sizes of the changed
|
|
53
|
+
* members differ, but a compressed header re-encodes entirely and the trailing block of the package
|
|
54
|
+
* (up to 32 KiB with the default chunker) was re-downloaded on every update. Cutting the header into
|
|
55
|
+
* its own small blocks makes that cost the header's few hundred bytes.
|
|
56
|
+
*/
|
|
57
|
+
export declare const ARCHIVE_HEADER_CHUNKER: ChunkerParams;
|
|
58
|
+
/**
|
|
59
|
+
* Locates the header of each 7z `archiveFiles` inside `artifact` (the archive itself, or an installer
|
|
60
|
+
* that embeds it verbatim) and returns an `ARCHIVE_HEADER_CHUNKER` region per located header, sorted by
|
|
61
|
+
* offset. The 32-byte 7z signature header names the header's offset and size; the signature header is
|
|
62
|
+
* found verbatim in the artifact (its CRCs make it unique, and byte-identical archives are matched to
|
|
63
|
+
* their own copies). An archive whose header is compressed, or that cannot be found, yields no region
|
|
64
|
+
* and is logged at debug/warn — the block map then falls back to the default chunker for those bytes.
|
|
65
|
+
*/
|
|
66
|
+
export declare function locateArchiveHeaderRegions(artifact: string, archiveFiles: Array<string>): Promise<Array<BlockMapRegion>>;
|
|
67
|
+
/** A stored member located verbatim in an artifact: the member file and its block map region there. */
|
|
68
|
+
export interface StoredMember {
|
|
69
|
+
file: string;
|
|
70
|
+
region: BlockMapRegion;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Forced v3 block boundaries for the stored members that are asar archives: the start of the content
|
|
74
|
+
* region and of every packed file in it (from the asar header's offsets), as absolute artifact offsets.
|
|
75
|
+
* With these cuts a change inside one file never alters a block that also covers its neighbour, so an
|
|
76
|
+
* in-place edit costs its own blocks only. Members that are not asars contribute nothing.
|
|
77
|
+
*/
|
|
78
|
+
export declare function asarContentBoundaries(members: Array<StoredMember>): Promise<Array<number>>;
|
|
20
79
|
/**
|
|
21
80
|
* Locates each of `memberFiles` (absolute paths of files stored verbatim inside `artifact`) and returns
|
|
22
81
|
* a `STORED_MEMBER_CHUNKER` blockmap region per located file, sorted by offset. The regions never
|
|
@@ -25,10 +84,35 @@ export declare const STORED_MEMBER_CHUNKER: ChunkerParams;
|
|
|
25
84
|
* earlier member is skipped. A member file that does not exist, or that cannot be found verbatim, is
|
|
26
85
|
* logged at warn and skipped — the blockmap then falls back to the default chunker for those bytes;
|
|
27
86
|
* it never fails the build.
|
|
87
|
+
*
|
|
88
|
+
* The returned regions are the v2 regions; `toV3Regions` derives the v3 regions (same byte ranges,
|
|
89
|
+
* `STORED_MEMBER_CHUNKER_V3`) from them, so both maps are built from the same located ranges.
|
|
28
90
|
*/
|
|
29
91
|
export declare function locateStoredMemberRegions(artifact: string, memberFiles: Array<string>): Promise<Array<BlockMapRegion>>;
|
|
30
|
-
/** `
|
|
31
|
-
export declare function
|
|
92
|
+
/** `locateStoredMemberRegions` keeping which member each region belongs to (for `asarContentBoundaries`). */
|
|
93
|
+
export declare function locateStoredMembers(artifact: string, memberFiles: Array<string>): Promise<Array<StoredMember>>;
|
|
94
|
+
/** `BuildBlockMapOptions` for the `blockmap: "v2"` format, plus what only the `"v3"` format uses. */
|
|
95
|
+
export interface DifferentialBlockMapOptions extends BuildBlockMapOptions {
|
|
96
|
+
/**
|
|
97
|
+
* Forced block boundaries for the `"v3"` format only (`BuildBlockMapV3Options.boundaries`); a `"v2"` map keeps
|
|
98
|
+
* its chunking byte-for-byte, since every updater downloads it in full.
|
|
99
|
+
*/
|
|
100
|
+
v3Boundaries?: Array<number> | null;
|
|
101
|
+
}
|
|
102
|
+
/** Options for `appendBlockmap` / `createBlockmap` from located regions (any order) and optional v3 boundaries. */
|
|
103
|
+
export declare function toBlockMapOptions(regions: Array<BlockMapRegion>, v3Boundaries?: Array<number> | null): DifferentialBlockMapOptions | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Block map options of an installer that embeds its app packages verbatim: the regions of their stored `members` and, for the
|
|
106
|
+
* binary format only, those of the 7z headers of `archiveFiles` and a block boundary at every packed file of a stored asar. The
|
|
107
|
+
* JSON format uses neither, so its build does not read them.
|
|
108
|
+
*/
|
|
109
|
+
export declare function installerBlockMapOptions(installerPath: string, members: Array<StoredMember>, archiveFiles: Array<string>, format: BlockMapFormat): Promise<DifferentialBlockMapOptions | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* The v3 block map regions for the v2 `regions` (as returned by `locateStoredMemberRegions`): the same
|
|
112
|
+
* byte ranges, with `STORED_MEMBER_CHUNKER` swapped for `STORED_MEMBER_CHUNKER_V3`. Regions with any
|
|
113
|
+
* other chunker are kept as they are (a caller that chose its own parameters gets them in both maps).
|
|
114
|
+
*/
|
|
115
|
+
export declare function toV3Regions(regions: Array<BlockMapRegion> | null | undefined): Array<BlockMapRegion>;
|
|
32
116
|
export declare function createNsisWebDifferentialUpdateInfo(artifactPath: string, packageFiles: {
|
|
33
117
|
[arch: string]: PackageFileInfo;
|
|
34
118
|
}): {
|
|
@@ -36,7 +120,11 @@ export declare function createNsisWebDifferentialUpdateInfo(artifactPath: string
|
|
|
36
120
|
[arch: string]: PackageFileInfo;
|
|
37
121
|
};
|
|
38
122
|
} | null;
|
|
39
|
-
|
|
123
|
+
/**
|
|
124
|
+
* `storeArchiveHeader`: whether the 7z header is stored as is, for a build whose block map chunks it finely (the binary format,
|
|
125
|
+
* see `locateArchiveHeaderRegions`). With the JSON format the package stays byte-for-byte what earlier versions wrote.
|
|
126
|
+
*/
|
|
127
|
+
export declare function configureDifferentialAwareArchiveOptions(archiveOptions: ArchiveOptions, storeArchiveHeader: boolean): ArchiveOptions;
|
|
40
128
|
export declare function appendBlockmap(file: string, options?: BuildBlockMapOptions): Promise<BlockMapDataHolder>;
|
|
41
|
-
export declare function createBlockmap(file: string, target: Target, packager: PlatformPackager<any>, safeArtifactName: string | null, arch?: Arch | null, options?:
|
|
129
|
+
export declare function createBlockmap(file: string, target: Target, packager: PlatformPackager<any>, safeArtifactName: string | null, arch?: Arch | null, options?: DifferentialBlockMapOptions): Promise<BlockMapDataHolder>;
|
|
42
130
|
//# sourceMappingURL=differentialUpdateInfoBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"differentialUpdateInfoBuilder.d.ts","sourceRoot":"","sources":["../../src/targets/differentialUpdateInfoBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"differentialUpdateInfoBuilder.d.ts","sourceRoot":"","sources":["../../src/targets/differentialUpdateInfoBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA0C,MAAM,cAAc,CAAA;AAC3E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAA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EAAE,cAAc,EAAE,kBAAkB,EAAE,OAAO,GAAG,cAAc,CAsCpI;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAG9G;AAED,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,gBAAgB,CAAC,GAAG,CAAC,EAC/B,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,IAAI,GAAE,IAAI,GAAG,IAAW,EACxB,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,kBAAkB,CAAC,CAsB7B"}
|
|
@@ -1,8 +1,61 @@
|
|
|
1
|
-
import { exists, log } from "builder-util";
|
|
1
|
+
import { exists, InvalidConfigurationError, log } from "builder-util";
|
|
2
|
+
import { open, stat } from "fs/promises";
|
|
2
3
|
import * as path from "path";
|
|
4
|
+
import * as zlib from "zlib";
|
|
5
|
+
import { readAsarHeader } from "../asar/asar.js";
|
|
6
|
+
import { BINARY_BLOCK_MAP_MIN_UPDATER, BLOCK_MAP_FORMAT_DOCS_URL, isBinaryBlockMapSupported, resolveElectronUpdaterCompatibility } from "../util/electronUpdaterCompatibility.js";
|
|
3
7
|
import { buildBlockMap } from "./blockmap/blockmap.js";
|
|
4
|
-
import {
|
|
8
|
+
import { buildBlockMapV3 } from "./blockmap/blockmapV3.js";
|
|
9
|
+
import { findPreparedVerbatimRange, prepareVerbatimNeedle, prepareVerbatimNeedleFromBuffer } from "./blockmap/verbatimRange.js";
|
|
5
10
|
export const BLOCK_MAP_FILE_SUFFIX = ".blockmap";
|
|
11
|
+
/** The binary format: the default when `electronUpdaterCompatibility` allows it. */
|
|
12
|
+
export const BINARY_BLOCK_MAP_FORMAT = "v3";
|
|
13
|
+
/** The newest format electron-builder writes, what `blockmap: "latest"` selects when `electronUpdaterCompatibility` allows it. */
|
|
14
|
+
export const LATEST_BLOCK_MAP_FORMAT = "v3";
|
|
15
|
+
/**
|
|
16
|
+
* The format of the `.blockmap` files of a build. The map is read by the updater already installed in the users' apps, which
|
|
17
|
+
* `electronUpdaterCompatibility` describes, so:
|
|
18
|
+
*
|
|
19
|
+
* - unset: the binary format when the range allows only electron-updater 7 and later, else the JSON format (with a warning);
|
|
20
|
+
* - `"latest"`: the newest format the range allows (today the same; unlike unset, it follows future formats);
|
|
21
|
+
* - `"v2"`: the JSON format;
|
|
22
|
+
* - `"v3"`: the binary format, which fails the build when the range includes electron-updater versions that cannot read it.
|
|
23
|
+
*/
|
|
24
|
+
export function resolveBlockMapFormat(value, electronUpdaterCompatibility) {
|
|
25
|
+
if (value != null && value !== "latest" && value !== "v2" && value !== "v3") {
|
|
26
|
+
throw new InvalidConfigurationError(`"blockmap" must be "v2", "v3" or "latest", got ${JSON.stringify(value)}`);
|
|
27
|
+
}
|
|
28
|
+
const binarySupported = isBinaryBlockMapSupported(electronUpdaterCompatibility);
|
|
29
|
+
if (value === "v2") {
|
|
30
|
+
return "v2";
|
|
31
|
+
}
|
|
32
|
+
if (value === "v3") {
|
|
33
|
+
if (!binarySupported) {
|
|
34
|
+
throw new InvalidConfigurationError(`blockmap "v3" (the binary block map) needs electron-updater ${BINARY_BLOCK_MAP_MIN_UPDATER} or later in the installed apps, but electronUpdaterCompatibility ` +
|
|
35
|
+
`"${electronUpdaterCompatibility}" includes earlier versions. Raise electronUpdaterCompatibility to ">=7" once your installed apps ship electron-updater 7, ` +
|
|
36
|
+
`or set blockmap to "v2". See ${BLOCK_MAP_FORMAT_DOCS_URL}`);
|
|
37
|
+
}
|
|
38
|
+
return "v3";
|
|
39
|
+
}
|
|
40
|
+
if (!binarySupported) {
|
|
41
|
+
warnAboutJsonBlockMap(electronUpdaterCompatibility);
|
|
42
|
+
return "v2";
|
|
43
|
+
}
|
|
44
|
+
return value === "latest" ? LATEST_BLOCK_MAP_FORMAT : BINARY_BLOCK_MAP_FORMAT;
|
|
45
|
+
}
|
|
46
|
+
/** The format of the `.blockmap` files `packager` writes. */
|
|
47
|
+
export function getBlockMapFormat(packager) {
|
|
48
|
+
return resolveBlockMapFormat(packager.config.blockmap, resolveElectronUpdaterCompatibility(packager.platformOptions, packager.config));
|
|
49
|
+
}
|
|
50
|
+
function warnAboutJsonBlockMap(electronUpdaterCompatibility) {
|
|
51
|
+
// once per process — a build resolves the format per artifact
|
|
52
|
+
log.once("json-block-map").warn({
|
|
53
|
+
electronUpdaterCompatibility,
|
|
54
|
+
solution: `raise electronUpdaterCompatibility to ">=7" once your installed apps ship electron-updater ${BINARY_BLOCK_MAP_MIN_UPDATER}`,
|
|
55
|
+
docs: BLOCK_MAP_FORMAT_DOCS_URL,
|
|
56
|
+
}, `electron-builder v27 writes binary block maps, which electron-updater fetches in parts, but electronUpdaterCompatibility includes electron-updater ` +
|
|
57
|
+
`versions before ${BINARY_BLOCK_MAP_MIN_UPDATER}, which cannot read them: this build writes JSON block maps, downloaded in full on every update`);
|
|
58
|
+
}
|
|
6
59
|
/**
|
|
7
60
|
* Chunker parameters for a stored (`Copy`) archive member — e.g. `resources/app.asar` when
|
|
8
61
|
* `nsis.differentialPackage` is `"store-asar"` — whose bytes sit verbatim in the artifact. Such a member
|
|
@@ -15,6 +68,149 @@ export const BLOCK_MAP_FILE_SUFFIX = ".blockmap";
|
|
|
15
68
|
* in full on every update) grows faster than the block savings. `avg` must stay a power of two.
|
|
16
69
|
*/
|
|
17
70
|
export const STORED_MEMBER_CHUNKER = { min: 4096, avg: 8192, max: 16384 };
|
|
71
|
+
/**
|
|
72
|
+
* `STORED_MEMBER_CHUNKER` counterpart for the `blockmap: "v3"` format (the v3 map of `blockMapV3.ts`). A v3 map costs
|
|
73
|
+
* ~10 B per block in the file but an updater fetches only the super-groups, groups and records that
|
|
74
|
+
* changed, so the v2 trade-off (a finer chunker inflating a map that is re-downloaded in full) no longer
|
|
75
|
+
* applies and the stored member can be chunked at 512 B / 1 KiB / 2 KiB: a one-line change then costs
|
|
76
|
+
* one or two small blocks plus a few KB of map. `max` must fit a v3 record's 16-bit block size.
|
|
77
|
+
*/
|
|
78
|
+
export const STORED_MEMBER_CHUNKER_V3 = { min: 512, avg: 1024, max: 2048 };
|
|
79
|
+
/**
|
|
80
|
+
* Chunker of the 7z archive header region (`locateArchiveHeaderRegions`). The header of a differential
|
|
81
|
+
* package is stored uncompressed (`configureDifferentialAwareArchiveOptions`) and is a few hundred bytes
|
|
82
|
+
* to a few KB: file names, sizes and CRCs. Between two releases only the CRCs and sizes of the changed
|
|
83
|
+
* members differ, but a compressed header re-encodes entirely and the trailing block of the package
|
|
84
|
+
* (up to 32 KiB with the default chunker) was re-downloaded on every update. Cutting the header into
|
|
85
|
+
* its own small blocks makes that cost the header's few hundred bytes.
|
|
86
|
+
*/
|
|
87
|
+
export const ARCHIVE_HEADER_CHUNKER = { min: 256, avg: 512, max: 1024 };
|
|
88
|
+
const SEVEN_ZIP_SIGNATURE = Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c]);
|
|
89
|
+
const SEVEN_ZIP_SIGNATURE_HEADER_SIZE = 32;
|
|
90
|
+
/** First byte of a 7z header stored as is (`kHeader`); a compressed header starts with `kEncodedHeader` (0x17). */
|
|
91
|
+
const SEVEN_ZIP_HEADER_ID = 0x01;
|
|
92
|
+
async function readBytes(file, position, length) {
|
|
93
|
+
const handle = await open(file, "r");
|
|
94
|
+
try {
|
|
95
|
+
const buffer = Buffer.alloc(length);
|
|
96
|
+
const { bytesRead } = await handle.read(buffer, 0, length, position);
|
|
97
|
+
return bytesRead === length ? buffer : null;
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
await handle.close();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Locates the header of each 7z `archiveFiles` inside `artifact` (the archive itself, or an installer
|
|
105
|
+
* that embeds it verbatim) and returns an `ARCHIVE_HEADER_CHUNKER` region per located header, sorted by
|
|
106
|
+
* offset. The 32-byte 7z signature header names the header's offset and size; the signature header is
|
|
107
|
+
* found verbatim in the artifact (its CRCs make it unique, and byte-identical archives are matched to
|
|
108
|
+
* their own copies). An archive whose header is compressed, or that cannot be found, yields no region
|
|
109
|
+
* and is logged at debug/warn — the block map then falls back to the default chunker for those bytes.
|
|
110
|
+
*/
|
|
111
|
+
export async function locateArchiveHeaderRegions(artifact, archiveFiles) {
|
|
112
|
+
const regions = [];
|
|
113
|
+
const claimed = [];
|
|
114
|
+
const resumeOffsetByHash = new Map();
|
|
115
|
+
for (const archiveFile of archiveFiles) {
|
|
116
|
+
const signature = (await exists(archiveFile)) ? await readBytes(archiveFile, 0, SEVEN_ZIP_SIGNATURE_HEADER_SIZE) : null;
|
|
117
|
+
if (signature == null || !signature.subarray(0, SEVEN_ZIP_SIGNATURE.length).equals(SEVEN_ZIP_SIGNATURE)) {
|
|
118
|
+
log.debug({ artifact: log.filePath(artifact), archive: log.filePath(archiveFile) }, "not a 7z archive; no block map region for its header");
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// StartHeaderCRC (bytes 8-11) covers the next header's offset, size and CRC (bytes 12-31): an archive that fails it is not
|
|
122
|
+
// what 7-Zip wrote, and its offset and size must not become a block map region
|
|
123
|
+
if (zlib.crc32(signature.subarray(12, SEVEN_ZIP_SIGNATURE_HEADER_SIZE)) !== signature.readUInt32LE(8)) {
|
|
124
|
+
log.warn({
|
|
125
|
+
artifact: log.filePath(artifact),
|
|
126
|
+
archive: log.filePath(archiveFile),
|
|
127
|
+
}, "7z start header CRC mismatch; no block map region for the archive header");
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const headerOffset = SEVEN_ZIP_SIGNATURE_HEADER_SIZE + Number(signature.readBigUInt64LE(12));
|
|
131
|
+
const headerSize = Number(signature.readBigUInt64LE(20));
|
|
132
|
+
if (headerSize === 0) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
let start = 0;
|
|
136
|
+
if (path.resolve(artifact) !== path.resolve(archiveFile)) {
|
|
137
|
+
const needle = prepareVerbatimNeedleFromBuffer(signature, `${path.basename(archiveFile)} signature header`);
|
|
138
|
+
const range = await findUnclaimedVerbatimRange(artifact, needle, claimed, resumeOffsetByHash.get(needle.hash) ?? 0);
|
|
139
|
+
if (range == null) {
|
|
140
|
+
log.warn({ artifact: log.filePath(artifact), archive: log.filePath(archiveFile) }, "archive not found verbatim in artifact; no block map region for its header");
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
resumeOffsetByHash.set(needle.hash, range.offset + range.size);
|
|
144
|
+
claimed.push({ ...range, chunker: ARCHIVE_HEADER_CHUNKER });
|
|
145
|
+
start = range.offset;
|
|
146
|
+
}
|
|
147
|
+
// a region past the end of the artifact would fail the whole block map; without it, only the header's finer chunking is lost
|
|
148
|
+
if (start + headerOffset + headerSize > (await stat(artifact)).size) {
|
|
149
|
+
log.warn({
|
|
150
|
+
artifact: log.filePath(artifact),
|
|
151
|
+
archive: log.filePath(archiveFile),
|
|
152
|
+
offset: start + headerOffset,
|
|
153
|
+
size: headerSize,
|
|
154
|
+
}, "7z header extends past the end of the artifact; no block map region for it");
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const first = await readBytes(artifact, start + headerOffset, 1);
|
|
158
|
+
if (first == null || first[0] !== SEVEN_ZIP_HEADER_ID) {
|
|
159
|
+
log.debug({ artifact: log.filePath(artifact), archive: log.filePath(archiveFile) }, "archive header is compressed; no block map region for it");
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
log.info({ artifact: log.filePath(artifact), archive: log.filePath(archiveFile), offset: start + headerOffset, size: headerSize }, "located archive header region for block map");
|
|
163
|
+
regions.push({ offset: start + headerOffset, size: headerSize, chunker: ARCHIVE_HEADER_CHUNKER });
|
|
164
|
+
}
|
|
165
|
+
return regions.sort((a, b) => a.offset - b.offset);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Forced v3 block boundaries for the stored members that are asar archives: the start of the content
|
|
169
|
+
* region and of every packed file in it (from the asar header's offsets), as absolute artifact offsets.
|
|
170
|
+
* With these cuts a change inside one file never alters a block that also covers its neighbour, so an
|
|
171
|
+
* in-place edit costs its own blocks only. Members that are not asars contribute nothing.
|
|
172
|
+
*/
|
|
173
|
+
export async function asarContentBoundaries(members) {
|
|
174
|
+
const boundaries = new Set();
|
|
175
|
+
for (const { file, region } of members) {
|
|
176
|
+
let header;
|
|
177
|
+
let headerSize;
|
|
178
|
+
try {
|
|
179
|
+
;
|
|
180
|
+
({ header, size: headerSize } = await readAsarHeader(file));
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
log.debug({ member: log.filePath(file), reason: e.message }, "stored member is not an asar; no forced block boundaries for it");
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const contentStart = region.offset + 8 + headerSize;
|
|
187
|
+
const regionEnd = region.offset + region.size;
|
|
188
|
+
const collect = (node) => {
|
|
189
|
+
for (const child of Object.values(node.files ?? {})) {
|
|
190
|
+
if (child.files != null) {
|
|
191
|
+
collect(child);
|
|
192
|
+
}
|
|
193
|
+
else if (child.offset != null && !child.unpacked && child.link == null) {
|
|
194
|
+
const boundary = contentStart + parseInt(child.offset, 10);
|
|
195
|
+
if (boundary > region.offset && boundary < regionEnd) {
|
|
196
|
+
boundaries.add(boundary);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
collect(JSON.parse(header));
|
|
203
|
+
}
|
|
204
|
+
catch (e) {
|
|
205
|
+
log.debug({ member: log.filePath(file), reason: e.message }, "stored member has no parsable asar header; no forced block boundaries for it");
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (contentStart < regionEnd) {
|
|
209
|
+
boundaries.add(contentStart);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return [...boundaries].sort((a, b) => a - b);
|
|
213
|
+
}
|
|
18
214
|
/**
|
|
19
215
|
* Locates each of `memberFiles` (absolute paths of files stored verbatim inside `artifact`) and returns
|
|
20
216
|
* a `STORED_MEMBER_CHUNKER` blockmap region per located file, sorted by offset. The regions never
|
|
@@ -23,8 +219,16 @@ export const STORED_MEMBER_CHUNKER = { min: 4096, avg: 8192, max: 16384 };
|
|
|
23
219
|
* earlier member is skipped. A member file that does not exist, or that cannot be found verbatim, is
|
|
24
220
|
* logged at warn and skipped — the blockmap then falls back to the default chunker for those bytes;
|
|
25
221
|
* it never fails the build.
|
|
222
|
+
*
|
|
223
|
+
* The returned regions are the v2 regions; `toV3Regions` derives the v3 regions (same byte ranges,
|
|
224
|
+
* `STORED_MEMBER_CHUNKER_V3`) from them, so both maps are built from the same located ranges.
|
|
26
225
|
*/
|
|
27
226
|
export async function locateStoredMemberRegions(artifact, memberFiles) {
|
|
227
|
+
return (await locateStoredMembers(artifact, memberFiles)).map(it => it.region);
|
|
228
|
+
}
|
|
229
|
+
/** `locateStoredMemberRegions` keeping which member each region belongs to (for `asarContentBoundaries`). */
|
|
230
|
+
export async function locateStoredMembers(artifact, memberFiles) {
|
|
231
|
+
const members = [];
|
|
28
232
|
const regions = [];
|
|
29
233
|
// Byte-identical members have identical occurrences, and the copies are claimed in ascending order,
|
|
30
234
|
// so the scan for the next member with the same content resumes where its previous copy ended instead
|
|
@@ -43,9 +247,11 @@ export async function locateStoredMemberRegions(artifact, memberFiles) {
|
|
|
43
247
|
}
|
|
44
248
|
resumeOffsetByHash.set(needle.hash, range.offset + range.size);
|
|
45
249
|
log.info({ artifact: log.filePath(artifact), member: log.filePath(memberFile), offset: range.offset, size: range.size }, "located stored member region for block map");
|
|
46
|
-
|
|
250
|
+
const region = { ...range, chunker: STORED_MEMBER_CHUNKER };
|
|
251
|
+
regions.push(region);
|
|
252
|
+
members.push({ file: memberFile, region });
|
|
47
253
|
}
|
|
48
|
-
return
|
|
254
|
+
return members.sort((a, b) => a.region.offset - b.region.offset);
|
|
49
255
|
}
|
|
50
256
|
/**
|
|
51
257
|
* The first occurrence of `needle` in `artifact` at or after `startOffset` that does not overlap a
|
|
@@ -67,9 +273,39 @@ async function findUnclaimedVerbatimRange(artifact, needle, claimed, startOffset
|
|
|
67
273
|
startOffset = clash.offset + clash.size;
|
|
68
274
|
}
|
|
69
275
|
}
|
|
70
|
-
/**
|
|
71
|
-
export function toBlockMapOptions(regions) {
|
|
72
|
-
|
|
276
|
+
/** Options for `appendBlockmap` / `createBlockmap` from located regions (any order) and optional v3 boundaries. */
|
|
277
|
+
export function toBlockMapOptions(regions, v3Boundaries) {
|
|
278
|
+
if (regions.length === 0 && (v3Boundaries == null || v3Boundaries.length === 0)) {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
const options = { regions: [...regions].sort((a, b) => a.offset - b.offset) };
|
|
282
|
+
if (v3Boundaries != null && v3Boundaries.length > 0) {
|
|
283
|
+
options.v3Boundaries = v3Boundaries;
|
|
284
|
+
}
|
|
285
|
+
return options;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Block map options of an installer that embeds its app packages verbatim: the regions of their stored `members` and, for the
|
|
289
|
+
* binary format only, those of the 7z headers of `archiveFiles` and a block boundary at every packed file of a stored asar. The
|
|
290
|
+
* JSON format uses neither, so its build does not read them.
|
|
291
|
+
*/
|
|
292
|
+
export async function installerBlockMapOptions(installerPath, members, archiveFiles, format) {
|
|
293
|
+
const regions = members.map(it => it.region);
|
|
294
|
+
if (format !== BINARY_BLOCK_MAP_FORMAT) {
|
|
295
|
+
return toBlockMapOptions(regions);
|
|
296
|
+
}
|
|
297
|
+
return toBlockMapOptions([...regions, ...(await locateArchiveHeaderRegions(installerPath, archiveFiles))], await asarContentBoundaries(members));
|
|
298
|
+
}
|
|
299
|
+
function isSameChunker(a, b) {
|
|
300
|
+
return a.min === b.min && a.avg === b.avg && a.max === b.max;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The v3 block map regions for the v2 `regions` (as returned by `locateStoredMemberRegions`): the same
|
|
304
|
+
* byte ranges, with `STORED_MEMBER_CHUNKER` swapped for `STORED_MEMBER_CHUNKER_V3`. Regions with any
|
|
305
|
+
* other chunker are kept as they are (a caller that chose its own parameters gets them in both maps).
|
|
306
|
+
*/
|
|
307
|
+
export function toV3Regions(regions) {
|
|
308
|
+
return (regions ?? []).map(region => (isSameChunker(region.chunker, STORED_MEMBER_CHUNKER) ? { ...region, chunker: STORED_MEMBER_CHUNKER_V3 } : region));
|
|
73
309
|
}
|
|
74
310
|
export function createNsisWebDifferentialUpdateInfo(artifactPath, packageFiles) {
|
|
75
311
|
if (packageFiles == null) {
|
|
@@ -92,7 +328,11 @@ export function createNsisWebDifferentialUpdateInfo(artifactPath, packageFiles)
|
|
|
92
328
|
}
|
|
93
329
|
return { packages };
|
|
94
330
|
}
|
|
95
|
-
|
|
331
|
+
/**
|
|
332
|
+
* `storeArchiveHeader`: whether the 7z header is stored as is, for a build whose block map chunks it finely (the binary format,
|
|
333
|
+
* see `locateArchiveHeaderRegions`). With the JSON format the package stays byte-for-byte what earlier versions wrote.
|
|
334
|
+
*/
|
|
335
|
+
export function configureDifferentialAwareArchiveOptions(archiveOptions, storeArchiveHeader) {
|
|
96
336
|
/*
|
|
97
337
|
* dict size 64 MB: Full: 33,744.88 KB, To download: 17,630.3 KB (52%)
|
|
98
338
|
* dict size 16 MB: Full: 33,936.84 KB, To download: 16,175.9 KB (48%)
|
|
@@ -123,6 +363,12 @@ export function configureDifferentialAwareArchiveOptions(archiveOptions) {
|
|
|
123
363
|
archiveOptions.solid = false;
|
|
124
364
|
// do not allow to change compression level to avoid different packages
|
|
125
365
|
archiveOptions.compression = "normal";
|
|
366
|
+
// store the archive header as is: a compressed header re-encodes entirely when a single CRC changes,
|
|
367
|
+
// so every update re-downloaded the trailing block of the package; stored, only the changed CRCs and
|
|
368
|
+
// sizes differ and `locateArchiveHeaderRegions` chunks the header finely (ARCHIVE_HEADER_CHUNKER)
|
|
369
|
+
if (storeArchiveHeader) {
|
|
370
|
+
archiveOptions.isArchiveHeaderCompressed = false;
|
|
371
|
+
}
|
|
126
372
|
return archiveOptions;
|
|
127
373
|
}
|
|
128
374
|
export async function appendBlockmap(file, options) {
|
|
@@ -130,9 +376,19 @@ export async function appendBlockmap(file, options) {
|
|
|
130
376
|
return buildBlockMap(file, "deflate", undefined, options);
|
|
131
377
|
}
|
|
132
378
|
export async function createBlockmap(file, target, packager, safeArtifactName, arch = null, options) {
|
|
379
|
+
const format = getBlockMapFormat(packager);
|
|
133
380
|
const blockMapFile = `${file}${BLOCK_MAP_FILE_SUFFIX}`;
|
|
134
|
-
log.info({ blockMapFile: log.filePath(blockMapFile) }, "building block map");
|
|
135
|
-
|
|
381
|
+
log.info({ blockMapFile: log.filePath(blockMapFile), format }, "building block map");
|
|
382
|
+
let updateInfo;
|
|
383
|
+
if (format === "v2") {
|
|
384
|
+
updateInfo = await buildBlockMap(file, "gzip", blockMapFile, options == null ? undefined : { regions: options.regions });
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
// the stored members get the finer v2 chunker, and a stored asar a block boundary at every packed file
|
|
388
|
+
const built = await buildBlockMapV3(file, blockMapFile, { regions: toV3Regions(options?.regions), boundaries: options?.v3Boundaries });
|
|
389
|
+
log.debug({ blockMapFile: log.filePath(blockMapFile), blocks: built.blockCount, groups: built.groupCount }, "built block map");
|
|
390
|
+
updateInfo = { size: built.size, sha512: built.sha512 };
|
|
391
|
+
}
|
|
136
392
|
await packager.emitArtifactBuildCompleted({
|
|
137
393
|
file: blockMapFile,
|
|
138
394
|
safeArtifactName: safeArtifactName == null ? null : `${safeArtifactName}${BLOCK_MAP_FILE_SUFFIX}`,
|