app-builder-lib 26.16.1 → 26.18.0
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/out/asar/asarUtil.js +7 -2
- package/out/asar/asarUtil.js.map +1 -1
- package/out/forge-maker.d.ts +64 -0
- package/out/forge-maker.js +108 -2
- package/out/forge-maker.js.map +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/node-module-collector/index.js +48 -15
- package/out/node-module-collector/index.js.map +1 -1
- package/out/node-module-collector/moduleManager.d.ts +7 -1
- package/out/node-module-collector/moduleManager.js +2 -2
- package/out/node-module-collector/moduleManager.js.map +1 -1
- package/out/node-module-collector/nodeModulesCollector.d.ts +7 -3
- package/out/node-module-collector/nodeModulesCollector.js +14 -5
- package/out/node-module-collector/nodeModulesCollector.js.map +1 -1
- package/out/node-module-collector/pnpmNodeModulesCollector.d.ts +79 -0
- package/out/node-module-collector/pnpmNodeModulesCollector.js +248 -24
- package/out/node-module-collector/pnpmNodeModulesCollector.js.map +1 -1
- package/out/targets/FlatpakTarget.js +6 -1
- package/out/targets/FlatpakTarget.js.map +1 -1
- package/out/targets/archive.d.ts +12 -0
- package/out/targets/archive.js +45 -1
- package/out/targets/archive.js.map +1 -1
- package/out/targets/blockmap/blockmap.d.ts +43 -3
- package/out/targets/blockmap/blockmap.js +143 -16
- package/out/targets/blockmap/blockmap.js.map +1 -1
- package/out/targets/blockmap/verbatimRange.d.ts +43 -0
- package/out/targets/blockmap/verbatimRange.js +122 -0
- package/out/targets/blockmap/verbatimRange.js.map +1 -0
- package/out/targets/differentialUpdateInfoBuilder.d.ts +27 -2
- package/out/targets/differentialUpdateInfoBuilder.js +77 -5
- package/out/targets/differentialUpdateInfoBuilder.js.map +1 -1
- package/out/targets/nsis/NsisTarget.d.ts +35 -2
- package/out/targets/nsis/NsisTarget.js +121 -25
- package/out/targets/nsis/NsisTarget.js.map +1 -1
- package/out/targets/nsis/nsisOptions.d.ts +21 -3
- package/out/targets/nsis/nsisOptions.js.map +1 -1
- package/out/targets/nsis/nsisUtil.d.ts +7 -0
- package/out/targets/nsis/nsisUtil.js +14 -3
- package/out/targets/nsis/nsisUtil.js.map +1 -1
- package/out/targets/pkg.d.ts +16 -0
- package/out/targets/pkg.js +27 -0
- package/out/targets/pkg.js.map +1 -1
- package/out/targets/snap/core24.d.ts +2 -0
- package/out/targets/snap/core24.js +30 -7
- package/out/targets/snap/core24.js.map +1 -1
- package/out/targets/snap/coreLegacy.js +1 -2
- package/out/targets/snap/coreLegacy.js.map +1 -1
- package/out/util/appFileCopier.d.ts +5 -0
- package/out/util/appFileCopier.js +20 -2
- package/out/util/appFileCopier.js.map +1 -1
- package/out/version.d.ts +1 -1
- package/out/version.js +1 -1
- package/out/version.js.map +1 -1
- package/package.json +9 -7
- package/scheme.json +19 -7
package/out/targets/archive.js
CHANGED
|
@@ -150,6 +150,7 @@ function compute7zCompressArgs(format, options = {}) {
|
|
|
150
150
|
// 7z is very fast, so, use ultra compression
|
|
151
151
|
/** @internal */
|
|
152
152
|
async function archive(format, outFile, dirToArchive, options = {}) {
|
|
153
|
+
var _a;
|
|
153
154
|
const outFileStat = await (0, builder_util_1.statOrNull)(outFile);
|
|
154
155
|
const dirStat = await (0, builder_util_1.statOrNull)(dirToArchive);
|
|
155
156
|
if (outFileStat && dirStat && outFileStat.mtime > dirStat.mtime) {
|
|
@@ -163,6 +164,21 @@ async function archive(format, outFile, dirToArchive, options = {}) {
|
|
|
163
164
|
builder_util_1.log.warn({ reason: "7z doesn't support NFD-normalized filenames" }, `using zip`);
|
|
164
165
|
use7z = false;
|
|
165
166
|
}
|
|
167
|
+
// Resolve storedPaths before the main pass so they can be excluded from it. Member names are
|
|
168
|
+
// native-separator, relative to the 7za cwd (which differs with withoutDir), so the same string
|
|
169
|
+
// works as both the exact `-x!` exclude mask and the append argument.
|
|
170
|
+
const storedMembers = [];
|
|
171
|
+
for (const storedPath of (_a = options.storedPaths) !== null && _a !== void 0 ? _a : []) {
|
|
172
|
+
if (storedPath.includes("..")) {
|
|
173
|
+
throw new Error(`Stored archive path contains path traversal sequence: "${storedPath}"`);
|
|
174
|
+
}
|
|
175
|
+
if (await (0, builder_util_1.exists)(path.join(dirToArchive, storedPath))) {
|
|
176
|
+
storedMembers.push(path.normalize(options.withoutDir ? storedPath : path.join(path.basename(dirToArchive), storedPath)));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (storedMembers.length > 0 && !use7z) {
|
|
180
|
+
throw new Error("storedPaths is not supported with the native zip fallback");
|
|
181
|
+
}
|
|
166
182
|
if (use7z) {
|
|
167
183
|
const args = compute7zCompressArgs(format, options);
|
|
168
184
|
// Modern 7-Zip (24.09) dereferences symlinks by default; the 7-Zip 16.02 bundled before
|
|
@@ -175,8 +191,11 @@ async function archive(format, outFile, dirToArchive, options = {}) {
|
|
|
175
191
|
await (0, builder_util_1.unlinkIfExists)(outFile);
|
|
176
192
|
args.push(outFile, options.withoutDir ? "." : path.basename(dirToArchive));
|
|
177
193
|
args.push(...buildExcludeArgs(options.excluded, "-xr!"));
|
|
194
|
+
// `-x!` (exact, non-recursive) so only the member itself is skipped, never a same-named sibling
|
|
195
|
+
args.push(...storedMembers.map(member => `-x!${member}`));
|
|
196
|
+
const cwd = options.withoutDir ? dirToArchive : path.dirname(dirToArchive);
|
|
178
197
|
try {
|
|
179
|
-
await (0, builder_util_1.exec)(await (0, _7zip_1.getPath7za)(), args, { cwd
|
|
198
|
+
await (0, builder_util_1.exec)(await (0, _7zip_1.getPath7za)(), args, { cwd }, builder_util_1.debug7z.enabled);
|
|
180
199
|
}
|
|
181
200
|
catch (e) {
|
|
182
201
|
if (e.code === "ENOENT" && !(await (0, builder_util_1.exists)(dirToArchive))) {
|
|
@@ -186,6 +205,31 @@ async function archive(format, outFile, dirToArchive, options = {}) {
|
|
|
186
205
|
throw e;
|
|
187
206
|
}
|
|
188
207
|
}
|
|
208
|
+
if (storedMembers.length > 0) {
|
|
209
|
+
// Second pass: append the stored members with no compression. -mx=0 unconditionally — the
|
|
210
|
+
// compression-level env override must not reach these members (see storedPaths docs). The
|
|
211
|
+
// main pass's symlink, timestamp, and header-compression flags are mirrored so the option
|
|
212
|
+
// stays generic: the append rewrites the archive header and may itself store a symlink.
|
|
213
|
+
const appendArgs = debug7zArgs("a");
|
|
214
|
+
appendArgs.push("-mx=0");
|
|
215
|
+
if (options.preserveSymlinks) {
|
|
216
|
+
appendArgs.push("-snl");
|
|
217
|
+
}
|
|
218
|
+
if (!options.isRegularFile) {
|
|
219
|
+
appendArgs.push("-mtc=off");
|
|
220
|
+
}
|
|
221
|
+
if (format === "7z" || format.endsWith(".7z")) {
|
|
222
|
+
if (options.isArchiveHeaderCompressed === false) {
|
|
223
|
+
appendArgs.push("-mhc=off");
|
|
224
|
+
}
|
|
225
|
+
appendArgs.push("-mtm=off", "-mta=off");
|
|
226
|
+
}
|
|
227
|
+
else if (format === "zip") {
|
|
228
|
+
appendArgs.push("-mm=Copy", "-mcu");
|
|
229
|
+
}
|
|
230
|
+
appendArgs.push(outFile, ...storedMembers);
|
|
231
|
+
await (0, builder_util_1.exec)(await (0, _7zip_1.getPath7za)(), appendArgs, { cwd }, builder_util_1.debug7z.enabled);
|
|
232
|
+
}
|
|
189
233
|
}
|
|
190
234
|
else {
|
|
191
235
|
// macOS native zip (NFD fallback): -y preserves symlinks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/targets/archive.ts"],"names":[],"mappings":";;AA+BA,kBAiCC;AAsDD,wDAEC;AAkBD,sDA2EC;AAID,0BAwDC;AAjRD,+CAAqF;AACrF,uCAA+B;AAC/B,6BAA4B;AAC5B,6BAA4B;AAG5B,kCAAoD;AACpD,6CAA2D;AAC3D,4CAA6C;AAE7C,sGAAsG;AACtG,qGAAqG;AACrG,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,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Null, unlinkIfExists } from \"builder-util\"\nimport { move } from \"fs-extra\"\nimport * as path from \"path\"\nimport { create } from \"tar\"\nimport { TarOptionsWithAliasesAsync } from \"tar/dist/commonjs/options\"\nimport { TmpDir } from \"temp-file\"\nimport { CompressionLevel, Platform } from \"../core\"\nimport { getLinuxToolsMacToolset } from \"../toolsets/linux\"\nimport { getPath7za } from \"../toolsets/7zip\"\n\n// Values accepted by ELECTRON_BUILDER_7Z_FILTER (passed through as `-mf=<value>`). \"OFF\" disables the\n// branch/exec filter entirely (plain LZMA2); the rest are 7-Zip branch converters. 7za matches these\n// case-insensitively, so the value is canonicalized to uppercase before use.\nconst ALLOWED_7Z_FILTERS = new Set([\"OFF\", \"BCJ\", \"BCJ2\", \"ARM\", \"ARMT\", \"IA64\", \"PPC\", \"SPARC\", \"DELTA\"])\n\nfunction validateCompressionLevel(level: string): void {\n if (!/^[0-9]$/.test(level)) {\n throw new Error(`ELECTRON_BUILDER_COMPRESSION_LEVEL must be a single digit 0-9, got: \"${level}\"`)\n }\n}\n\ntype TarConfig = {\n compression: CompressionLevel | null | undefined\n format: string\n outFile: string\n dirToArchive: string\n isMacApp: boolean\n tempDirManager: TmpDir\n}\n\n/** @internal */\nexport async function tar({ compression, format, outFile, dirToArchive, isMacApp, tempDirManager }: TarConfig): Promise<void> {\n const tarFile = await tempDirManager.getTempFile({ suffix: \".tar\" })\n const tarArgs: TarOptionsWithAliasesAsync = {\n file: tarFile,\n portable: true,\n cwd: dirToArchive,\n prefix: path.basename(outFile, `.${format}`),\n }\n let tarDirectory = \".\"\n if (isMacApp) {\n delete tarArgs.prefix\n tarArgs.cwd = path.dirname(dirToArchive)\n tarDirectory = path.basename(dirToArchive)\n }\n\n await Promise.all([\n create(tarArgs, [tarDirectory]),\n // remove file before - 7z doesn't overwrite file, but update\n unlinkIfExists(outFile),\n ])\n\n if (format === \"tar.lz\") {\n const lzipPath = process.platform === \"darwin\" ? (await getLinuxToolsMacToolset()).lzip : \"lzip\"\n await exec(lzipPath, [compression === \"store\" ? \"-1\" : \"-9\", \"--keep\" /* keep (don't delete) input files */, tarFile])\n // lzip creates the output file in the same directory as the input with a .lz suffix\n await move(`${tarFile}.lz`, outFile)\n return\n }\n\n const compressFormat = format === \"tar.xz\" ? \"xz\" : format === \"tar.bz2\" ? \"bzip2\" : \"gzip\"\n const args = compute7zCompressArgs(compressFormat, { isRegularFile: true, method: \"DEFAULT\", compression })\n args.push(outFile, tarFile)\n await exec(await getPath7za(), args, { cwd: path.dirname(dirToArchive) }, debug7z.enabled)\n}\n\nexport interface ArchiveOptions {\n compression?: CompressionLevel | null\n\n /**\n * @default false\n */\n withoutDir?: boolean\n\n /**\n * @default true\n */\n solid?: boolean\n\n /**\n * @default true\n */\n isArchiveHeaderCompressed?: boolean\n\n dictSize?: number\n excluded?: Array<string> | null\n\n // DEFAULT allows to disable custom logic and do not pass method switch at all\n method?: \"Copy\" | \"LZMA\" | \"Deflate\" | \"DEFAULT\"\n\n isRegularFile?: boolean\n\n /**\n * Preserve symlinks (e.g. macOS .framework `Versions/Current`) instead of dereferencing them.\n * Passes `-snl` to 7za — modern 7-Zip derefs by default, which breaks bundle codesigning. See #9846.\n * @default false\n */\n preserveSymlinks?: boolean\n\n /**\n * Restrict the 7z filter to one the install-time extractor (the self-vendored Nsis7z plugin) can\n * decode. Modern 7za (24.09) auto-applies a CPU branch converter to executable content at\n * `-mx>=1` — `BCJ2` on x86/x64 and `ARM64` on arm64 — which that decoder silently skips, dropping\n * every executable from the install. When set, the archive is pinned to the single-stream `BCJ`\n * filter while compressing (decodable, and the best-ratio filter that decoder supports) and to\n * plain `Copy` while storing. Deliberately NOT overridable by `ELECTRON_BUILDER_7Z_FILTER`, which\n * could otherwise reintroduce an unreadable archive. Only affects the 7z format. See #9983.\n * @default false\n */\n installTimeDecodable?: boolean\n}\n\n/**\n * Whether archives for the given target platform should preserve symlinks (i.e. pass `-snl`).\n * Non-Windows targets preserve them: macOS `.framework` bundles need them for codesigning (#9846)\n * and Linux bundles may legitimately contain them. Windows dereferences because restoring symlinks\n * there requires elevated privileges. Keyed on the target platform, not the build host.\n */\nexport function shouldPreserveSymlinks(platform: Platform): boolean {\n return platform !== Platform.WINDOWS\n}\n\n/**\n * Builds the exclude switches for the given masks, rejecting any pattern that contains a path\n * traversal sequence. `prefix` is the tool-specific flag (`-xr!` for 7za, `-x` for native zip).\n */\nfunction buildExcludeArgs(excluded: Array<string> | null | undefined, prefix: string): Array<string> {\n if (excluded == null) {\n return []\n }\n return excluded.map(mask => {\n if (mask.includes(\"..\")) {\n throw new Error(`Excluded archive pattern contains path traversal sequence: \"${mask}\"`)\n }\n return `${prefix}${mask}`\n })\n}\n\nexport function compute7zCompressArgs(format: string, options: ArchiveOptions = {}) {\n let storeOnly = options.compression === \"store\"\n const args = debug7zArgs(\"a\")\n\n const compressionLevel = process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL\n if (compressionLevel != null) {\n validateCompressionLevel(compressionLevel)\n storeOnly = false // env var overrides \"store\" config\n args.push(`-mx=${compressionLevel}`)\n } else if (storeOnly) {\n // -mx=0 is the universal \"no compression\" flag across all formats (zip, 7z, gzip, xz, bzip2).\n // -mm=Copy would only be valid for zip/7z and causes E_INVALIDARG on xz/gzip/bzip2.\n args.push(\"-mx=0\")\n } else {\n const isZip = format === \"zip\"\n // ZIP uses level 7 by default; everything else (7z, gzip, xz, bzip2) uses level 9\n args.push(\"-mx=\" + (isZip && options.compression !== \"maximum\" ? \"7\" : \"9\"))\n if (isZip && options.compression === \"maximum\") {\n // http://superuser.com/a/742034\n args.push(\"-mfb=258\", \"-mpass=15\")\n }\n }\n\n if (options.dictSize != null) {\n args.push(`-md=${options.dictSize}m`)\n }\n\n // Disable NTFS timestamps for reproducible archives\n if (!options.isRegularFile) {\n args.push(\"-mtc=off\")\n }\n\n if (format === \"7z\" || format.endsWith(\".7z\")) {\n if (options.solid === false) {\n args.push(\"-ms=off\")\n }\n\n if (options.isArchiveHeaderCompressed === false) {\n args.push(\"-mhc=off\")\n }\n\n // Branch/exec filter selection. installTimeDecodable archives are unpacked by the self-vendored\n // Nsis7z extractor, whose decoder only understands plain LZMA2/Copy and the single-stream BCJ\n // filter — not the CPU branch converters modern 7za auto-applies (BCJ2 on x86/x64, ARM64 on\n // arm64). So pin them to BCJ while compressing (the best filter that decoder can read; Copy\n // needs none) and do not honor ELECTRON_BUILDER_7Z_FILTER, which could reintroduce an unreadable\n // archive. Any other 7z archive may use ELECTRON_BUILDER_7Z_FILTER, else 7za's auto-selection.\n if (options.installTimeDecodable) {\n if (!storeOnly) {\n args.push(\"-mf=BCJ\")\n }\n } else {\n const sevenZFilter = process.env.ELECTRON_BUILDER_7Z_FILTER\n if (sevenZFilter) {\n const canonicalFilter = sevenZFilter.toUpperCase()\n if (!ALLOWED_7Z_FILTERS.has(canonicalFilter)) {\n throw new Error(`ELECTRON_BUILDER_7Z_FILTER must be one of: ${[...ALLOWED_7Z_FILTERS].join(\", \")}`)\n }\n args.push(`-mf=${canonicalFilter}`)\n }\n }\n\n args.push(\"-mtm=off\", \"-mta=off\")\n }\n\n if (options.method != null && options.method !== \"DEFAULT\") {\n args.push(`-mm=${options.method}`)\n } else if (format === \"zip\") {\n // -mm is only set explicitly for zip (Deflate/Copy) and includes the UTF-8 flag.\n // For all other formats the codec is implicit from the output file extension.\n args.push(`-mm=${storeOnly ? \"Copy\" : \"Deflate\"}`)\n args.push(\"-mcu\")\n }\n\n return args\n}\n\n// 7z is very fast, so, use ultra compression\n/** @internal */\nexport async function archive(format: string, outFile: string, dirToArchive: string, options: ArchiveOptions = {}): Promise<string> {\n const outFileStat = await statOrNull(outFile)\n const dirStat = await statOrNull(dirToArchive)\n if (outFileStat && dirStat && outFileStat.mtime > dirStat.mtime) {\n log.info({ reason: \"Archive file is up to date\", outFile }, `skipped archiving`)\n return outFile\n }\n\n // Use 7za for all formats (matches pre-26.15 behavior). Native macOS `zip` is only a\n // fallback for NFD-normalized filenames, which 7za mangles.\n let use7z = true\n if (process.platform === \"darwin\" && format === \"zip\" && dirToArchive.normalize(\"NFC\") !== dirToArchive) {\n log.warn({ reason: \"7z doesn't support NFD-normalized filenames\" }, `using zip`)\n use7z = false\n }\n\n if (use7z) {\n const args = compute7zCompressArgs(format, options)\n // Modern 7-Zip (24.09) dereferences symlinks by default; the 7-Zip 16.02 bundled before\n // 26.15 stored them as links. Without -snl, a macOS .framework `Versions/Current` extracts\n // as a real directory → codesign \"bundle format is ambiguous\" → breaks Squirrel.Mac\n // auto-update (#9846). Callers enable it for all non-Windows targets (see ArchiveTarget).\n if (options.preserveSymlinks) {\n args.push(\"-snl\")\n }\n await unlinkIfExists(outFile)\n args.push(outFile, options.withoutDir ? \".\" : path.basename(dirToArchive))\n args.push(...buildExcludeArgs(options.excluded, \"-xr!\"))\n\n try {\n await exec(await getPath7za(), args, { cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive) }, debug7z.enabled)\n } catch (e: any) {\n if (e.code === \"ENOENT\" && !(await exists(dirToArchive))) {\n throw new Error(`Cannot create archive: \"${dirToArchive}\" doesn't exist`)\n } else {\n throw e\n }\n }\n } else {\n // macOS native zip (NFD fallback): -y preserves symlinks\n const args = [\"-q\", \"-r\", \"-y\"]\n if (debug7z.enabled) {\n args.push(\"-v\")\n }\n if (options.compression === \"store\") {\n args.push(\"-0\")\n } else {\n args.push(options.compression === \"maximum\" ? \"-9\" : \"-7\")\n }\n await unlinkIfExists(outFile)\n args.push(outFile, options.withoutDir ? \".\" : path.basename(dirToArchive))\n args.push(...buildExcludeArgs(options.excluded, \"-x\"))\n await exec(\"zip\", args, { cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive) }, debug7z.enabled)\n }\n\n return outFile\n}\n\nfunction debug7zArgs(command: \"a\" | \"x\"): Array<string> {\n const args = [command, \"-bd\"]\n if (debug7z.enabled) {\n args.push(\"-bb\")\n }\n return args\n}\n"]}
|
|
1
|
+
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/targets/archive.ts"],"names":[],"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C,IAAI,CAAC,IAAI,CAAC,CAAA;QACjB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC5D,CAAC;QACD,MAAM,IAAA,6BAAc,EAAC,OAAO,CAAC,CAAA;QAC7B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAA;QAC1E,IAAI,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;QACtD,MAAM,IAAA,mBAAI,EAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,EAAE,sBAAO,CAAC,OAAO,CAAC,CAAA;IACnH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,WAAW,CAAC,OAAkB;IACrC,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7B,IAAI,sBAAO,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAClB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { debug7z, exec, exists, log, statOrNull, unlinkIfExists } from \"builder-util\"\nimport { move } from \"fs-extra\"\nimport * as path from \"path\"\nimport { create } from \"tar\"\nimport { TarOptionsWithAliasesAsync } from \"tar/dist/commonjs/options\"\nimport { TmpDir } from \"temp-file\"\nimport { CompressionLevel, Platform } from \"../core\"\nimport { getLinuxToolsMacToolset } from \"../toolsets/linux\"\nimport { getPath7za } from \"../toolsets/7zip\"\n\n// Values accepted by ELECTRON_BUILDER_7Z_FILTER (passed through as `-mf=<value>`). \"OFF\" disables the\n// branch/exec filter entirely (plain LZMA2); the rest are 7-Zip branch converters. 7za matches these\n// case-insensitively, so the value is canonicalized to uppercase before use.\nconst ALLOWED_7Z_FILTERS = new Set([\"OFF\", \"BCJ\", \"BCJ2\", \"ARM\", \"ARMT\", \"IA64\", \"PPC\", \"SPARC\", \"DELTA\"])\n\nfunction validateCompressionLevel(level: string): void {\n if (!/^[0-9]$/.test(level)) {\n throw new Error(`ELECTRON_BUILDER_COMPRESSION_LEVEL must be a single digit 0-9, got: \"${level}\"`)\n }\n}\n\ntype TarConfig = {\n compression: CompressionLevel | null | undefined\n format: string\n outFile: string\n dirToArchive: string\n isMacApp: boolean\n tempDirManager: TmpDir\n}\n\n/** @internal */\nexport async function tar({ compression, format, outFile, dirToArchive, isMacApp, tempDirManager }: TarConfig): Promise<void> {\n const tarFile = await tempDirManager.getTempFile({ suffix: \".tar\" })\n const tarArgs: TarOptionsWithAliasesAsync = {\n file: tarFile,\n portable: true,\n cwd: dirToArchive,\n prefix: path.basename(outFile, `.${format}`),\n }\n let tarDirectory = \".\"\n if (isMacApp) {\n delete tarArgs.prefix\n tarArgs.cwd = path.dirname(dirToArchive)\n tarDirectory = path.basename(dirToArchive)\n }\n\n await Promise.all([\n create(tarArgs, [tarDirectory]),\n // remove file before - 7z doesn't overwrite file, but update\n unlinkIfExists(outFile),\n ])\n\n if (format === \"tar.lz\") {\n const lzipPath = process.platform === \"darwin\" ? (await getLinuxToolsMacToolset()).lzip : \"lzip\"\n await exec(lzipPath, [compression === \"store\" ? \"-1\" : \"-9\", \"--keep\" /* keep (don't delete) input files */, tarFile])\n // lzip creates the output file in the same directory as the input with a .lz suffix\n await move(`${tarFile}.lz`, outFile)\n return\n }\n\n const compressFormat = format === \"tar.xz\" ? \"xz\" : format === \"tar.bz2\" ? \"bzip2\" : \"gzip\"\n const args = compute7zCompressArgs(compressFormat, { isRegularFile: true, method: \"DEFAULT\", compression })\n args.push(outFile, tarFile)\n await exec(await getPath7za(), args, { cwd: path.dirname(dirToArchive) }, debug7z.enabled)\n}\n\nexport interface ArchiveOptions {\n compression?: CompressionLevel | null\n\n /**\n * @default false\n */\n withoutDir?: boolean\n\n /**\n * @default true\n */\n solid?: boolean\n\n /**\n * @default true\n */\n isArchiveHeaderCompressed?: boolean\n\n dictSize?: number\n excluded?: Array<string> | null\n\n // DEFAULT allows to disable custom logic and do not pass method switch at all\n method?: \"Copy\" | \"LZMA\" | \"Deflate\" | \"DEFAULT\"\n\n isRegularFile?: boolean\n\n /**\n * Preserve symlinks (e.g. macOS .framework `Versions/Current`) instead of dereferencing them.\n * Passes `-snl` to 7za — modern 7-Zip derefs by default, which breaks bundle codesigning. See #9846.\n * @default false\n */\n preserveSymlinks?: boolean\n\n /**\n * Paths, relative to the archived directory, to append as uncompressed (`Copy`) members instead of\n * compressing them with the rest of the archive. Differential updates diff the *compressed* archive\n * with a content-defined blockmap, and a large compressed member (an asar) diverges wholesale from\n * its previous version on any change — storing it keeps unchanged regions byte-identical between\n * builds, so the delta stays proportional to what actually changed. The stored members are excluded\n * from the main (compressed) pass and appended in a second 7za invocation with `-mx=0`; the\n * `ELECTRON_BUILDER_COMPRESSION_LEVEL` override deliberately does not apply to them (byte-stability\n * is the point), while `preserveSymlinks` and `isArchiveHeaderCompressed` are mirrored into the\n * append pass. Paths that do not exist are skipped. Not supported by the native-zip NFD fallback.\n */\n storedPaths?: Array<string> | null\n\n /**\n * Restrict the 7z filter to one the install-time extractor (the self-vendored Nsis7z plugin) can\n * decode. Modern 7za (24.09) auto-applies a CPU branch converter to executable content at\n * `-mx>=1` — `BCJ2` on x86/x64 and `ARM64` on arm64 — which that decoder silently skips, dropping\n * every executable from the install. When set, the archive is pinned to the single-stream `BCJ`\n * filter while compressing (decodable, and the best-ratio filter that decoder supports) and to\n * plain `Copy` while storing. Deliberately NOT overridable by `ELECTRON_BUILDER_7Z_FILTER`, which\n * could otherwise reintroduce an unreadable archive. Only affects the 7z format. See #9983.\n * @default false\n */\n installTimeDecodable?: boolean\n}\n\n/**\n * Whether archives for the given target platform should preserve symlinks (i.e. pass `-snl`).\n * Non-Windows targets preserve them: macOS `.framework` bundles need them for codesigning (#9846)\n * and Linux bundles may legitimately contain them. Windows dereferences because restoring symlinks\n * there requires elevated privileges. Keyed on the target platform, not the build host.\n */\nexport function shouldPreserveSymlinks(platform: Platform): boolean {\n return platform !== Platform.WINDOWS\n}\n\n/**\n * Builds the exclude switches for the given masks, rejecting any pattern that contains a path\n * traversal sequence. `prefix` is the tool-specific flag (`-xr!` for 7za, `-x` for native zip).\n */\nfunction buildExcludeArgs(excluded: Array<string> | null | undefined, prefix: string): Array<string> {\n if (excluded == null) {\n return []\n }\n return excluded.map(mask => {\n if (mask.includes(\"..\")) {\n throw new Error(`Excluded archive pattern contains path traversal sequence: \"${mask}\"`)\n }\n return `${prefix}${mask}`\n })\n}\n\nexport function compute7zCompressArgs(format: string, options: ArchiveOptions = {}) {\n let storeOnly = options.compression === \"store\"\n const args = debug7zArgs(\"a\")\n\n const compressionLevel = process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL\n if (compressionLevel != null) {\n validateCompressionLevel(compressionLevel)\n storeOnly = false // env var overrides \"store\" config\n args.push(`-mx=${compressionLevel}`)\n } else if (storeOnly) {\n // -mx=0 is the universal \"no compression\" flag across all formats (zip, 7z, gzip, xz, bzip2).\n // -mm=Copy would only be valid for zip/7z and causes E_INVALIDARG on xz/gzip/bzip2.\n args.push(\"-mx=0\")\n } else {\n const isZip = format === \"zip\"\n // ZIP uses level 7 by default; everything else (7z, gzip, xz, bzip2) uses level 9\n args.push(\"-mx=\" + (isZip && options.compression !== \"maximum\" ? \"7\" : \"9\"))\n if (isZip && options.compression === \"maximum\") {\n // http://superuser.com/a/742034\n args.push(\"-mfb=258\", \"-mpass=15\")\n }\n }\n\n if (options.dictSize != null) {\n args.push(`-md=${options.dictSize}m`)\n }\n\n // Disable NTFS timestamps for reproducible archives\n if (!options.isRegularFile) {\n args.push(\"-mtc=off\")\n }\n\n if (format === \"7z\" || format.endsWith(\".7z\")) {\n if (options.solid === false) {\n args.push(\"-ms=off\")\n }\n\n if (options.isArchiveHeaderCompressed === false) {\n args.push(\"-mhc=off\")\n }\n\n // Branch/exec filter selection. installTimeDecodable archives are unpacked by the self-vendored\n // Nsis7z extractor, whose decoder only understands plain LZMA2/Copy and the single-stream BCJ\n // filter — not the CPU branch converters modern 7za auto-applies (BCJ2 on x86/x64, ARM64 on\n // arm64). So pin them to BCJ while compressing (the best filter that decoder can read; Copy\n // needs none) and do not honor ELECTRON_BUILDER_7Z_FILTER, which could reintroduce an unreadable\n // archive. Any other 7z archive may use ELECTRON_BUILDER_7Z_FILTER, else 7za's auto-selection.\n if (options.installTimeDecodable) {\n if (!storeOnly) {\n args.push(\"-mf=BCJ\")\n }\n } else {\n const sevenZFilter = process.env.ELECTRON_BUILDER_7Z_FILTER\n if (sevenZFilter) {\n const canonicalFilter = sevenZFilter.toUpperCase()\n if (!ALLOWED_7Z_FILTERS.has(canonicalFilter)) {\n throw new Error(`ELECTRON_BUILDER_7Z_FILTER must be one of: ${[...ALLOWED_7Z_FILTERS].join(\", \")}`)\n }\n args.push(`-mf=${canonicalFilter}`)\n }\n }\n\n args.push(\"-mtm=off\", \"-mta=off\")\n }\n\n if (options.method != null && options.method !== \"DEFAULT\") {\n args.push(`-mm=${options.method}`)\n } else if (format === \"zip\") {\n // -mm is only set explicitly for zip (Deflate/Copy) and includes the UTF-8 flag.\n // For all other formats the codec is implicit from the output file extension.\n args.push(`-mm=${storeOnly ? \"Copy\" : \"Deflate\"}`)\n args.push(\"-mcu\")\n }\n\n return args\n}\n\n// 7z is very fast, so, use ultra compression\n/** @internal */\nexport async function archive(format: string, outFile: string, dirToArchive: string, options: ArchiveOptions = {}): Promise<string> {\n const outFileStat = await statOrNull(outFile)\n const dirStat = await statOrNull(dirToArchive)\n if (outFileStat && dirStat && outFileStat.mtime > dirStat.mtime) {\n log.info({ reason: \"Archive file is up to date\", outFile }, `skipped archiving`)\n return outFile\n }\n\n // Use 7za for all formats (matches pre-26.15 behavior). Native macOS `zip` is only a\n // fallback for NFD-normalized filenames, which 7za mangles.\n let use7z = true\n if (process.platform === \"darwin\" && format === \"zip\" && dirToArchive.normalize(\"NFC\") !== dirToArchive) {\n log.warn({ reason: \"7z doesn't support NFD-normalized filenames\" }, `using zip`)\n use7z = false\n }\n\n // Resolve storedPaths before the main pass so they can be excluded from it. Member names are\n // native-separator, relative to the 7za cwd (which differs with withoutDir), so the same string\n // works as both the exact `-x!` exclude mask and the append argument.\n const storedMembers: Array<string> = []\n for (const storedPath of options.storedPaths ?? []) {\n if (storedPath.includes(\"..\")) {\n throw new Error(`Stored archive path contains path traversal sequence: \"${storedPath}\"`)\n }\n if (await exists(path.join(dirToArchive, storedPath))) {\n storedMembers.push(path.normalize(options.withoutDir ? storedPath : path.join(path.basename(dirToArchive), storedPath)))\n }\n }\n if (storedMembers.length > 0 && !use7z) {\n throw new Error(\"storedPaths is not supported with the native zip fallback\")\n }\n\n if (use7z) {\n const args = compute7zCompressArgs(format, options)\n // Modern 7-Zip (24.09) dereferences symlinks by default; the 7-Zip 16.02 bundled before\n // 26.15 stored them as links. Without -snl, a macOS .framework `Versions/Current` extracts\n // as a real directory → codesign \"bundle format is ambiguous\" → breaks Squirrel.Mac\n // auto-update (#9846). Callers enable it for all non-Windows targets (see ArchiveTarget).\n if (options.preserveSymlinks) {\n args.push(\"-snl\")\n }\n await unlinkIfExists(outFile)\n args.push(outFile, options.withoutDir ? \".\" : path.basename(dirToArchive))\n args.push(...buildExcludeArgs(options.excluded, \"-xr!\"))\n // `-x!` (exact, non-recursive) so only the member itself is skipped, never a same-named sibling\n args.push(...storedMembers.map(member => `-x!${member}`))\n\n const cwd = options.withoutDir ? dirToArchive : path.dirname(dirToArchive)\n try {\n await exec(await getPath7za(), args, { cwd }, debug7z.enabled)\n } catch (e: any) {\n if (e.code === \"ENOENT\" && !(await exists(dirToArchive))) {\n throw new Error(`Cannot create archive: \"${dirToArchive}\" doesn't exist`)\n } else {\n throw e\n }\n }\n\n if (storedMembers.length > 0) {\n // Second pass: append the stored members with no compression. -mx=0 unconditionally — the\n // compression-level env override must not reach these members (see storedPaths docs). The\n // main pass's symlink, timestamp, and header-compression flags are mirrored so the option\n // stays generic: the append rewrites the archive header and may itself store a symlink.\n const appendArgs = debug7zArgs(\"a\")\n appendArgs.push(\"-mx=0\")\n if (options.preserveSymlinks) {\n appendArgs.push(\"-snl\")\n }\n if (!options.isRegularFile) {\n appendArgs.push(\"-mtc=off\")\n }\n if (format === \"7z\" || format.endsWith(\".7z\")) {\n if (options.isArchiveHeaderCompressed === false) {\n appendArgs.push(\"-mhc=off\")\n }\n appendArgs.push(\"-mtm=off\", \"-mta=off\")\n } else if (format === \"zip\") {\n appendArgs.push(\"-mm=Copy\", \"-mcu\")\n }\n appendArgs.push(outFile, ...storedMembers)\n await exec(await getPath7za(), appendArgs, { cwd }, debug7z.enabled)\n }\n } else {\n // macOS native zip (NFD fallback): -y preserves symlinks\n const args = [\"-q\", \"-r\", \"-y\"]\n if (debug7z.enabled) {\n args.push(\"-v\")\n }\n if (options.compression === \"store\") {\n args.push(\"-0\")\n } else {\n args.push(options.compression === \"maximum\" ? \"-9\" : \"-7\")\n }\n await unlinkIfExists(outFile)\n args.push(outFile, options.withoutDir ? \".\" : path.basename(dirToArchive))\n args.push(...buildExcludeArgs(options.excluded, \"-x\"))\n await exec(\"zip\", args, { cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive) }, debug7z.enabled)\n }\n\n return outFile\n}\n\nfunction debug7zArgs(command: \"a\" | \"x\"): Array<string> {\n const args = [command, \"-bd\"]\n if (debug7z.enabled) {\n args.push(\"-bb\")\n }\n return args\n}\n"]}
|
|
@@ -1,16 +1,56 @@
|
|
|
1
1
|
import { BlockMapDataHolder } from "builder-util-runtime";
|
|
2
2
|
export type CompressionFormat = "deflate" | "gzip";
|
|
3
|
+
/** Rabin content-defined chunker parameters. `avg` must be a power of two; `min` < `avg` <= `max`. */
|
|
4
|
+
export interface ChunkerParams {
|
|
5
|
+
min: number;
|
|
6
|
+
avg: number;
|
|
7
|
+
max: number;
|
|
8
|
+
}
|
|
9
|
+
/** Default chunker (go-rabin defaults): 8 KB min / 16 KB avg / 32 KB max. */
|
|
10
|
+
export declare const DEFAULT_CHUNKER: ChunkerParams;
|
|
11
|
+
/**
|
|
12
|
+
* A byte range of the input that should be chunked with its own parameters — e.g. a stored
|
|
13
|
+
* (uncompressed) archive member that is expected to change in small, localized ways between
|
|
14
|
+
* releases, where finer blocks make a differential download proportional to the change.
|
|
15
|
+
* Chunk boundaries are forced at both edges of every region, so the blocks inside a region
|
|
16
|
+
* depend only on the region's own bytes.
|
|
17
|
+
*/
|
|
18
|
+
export interface BlockMapRegion {
|
|
19
|
+
offset: number;
|
|
20
|
+
size: number;
|
|
21
|
+
chunker: ChunkerParams;
|
|
22
|
+
}
|
|
23
|
+
export interface BuildBlockMapOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Byte ranges of the input that are chunked with their own `ChunkerParams`; bytes outside every
|
|
26
|
+
* region use `DEFAULT_CHUNKER`. Regions must be ascending, non-overlapping and lie entirely
|
|
27
|
+
* within the input file (an empty list or `null` is equivalent to "no regions").
|
|
28
|
+
*
|
|
29
|
+
* A chunk boundary is forced at the start and at the end of every region: any pending chunk is
|
|
30
|
+
* emitted when the region begins and the last chunk of the region is emitted when it ends. Because
|
|
31
|
+
* the chunker state is reset at every boundary, the sequence of (checksum, size) blocks produced
|
|
32
|
+
* for a region depends only on the region's own bytes — it is identical for the same bytes placed
|
|
33
|
+
* at a different offset or surrounded by different data.
|
|
34
|
+
*/
|
|
35
|
+
regions?: Array<BlockMapRegion> | null;
|
|
36
|
+
}
|
|
3
37
|
/**
|
|
4
38
|
* Build a content-defined block map for `inFile` using Rabin fingerprinting.
|
|
5
39
|
*
|
|
6
|
-
* Files are processed via streaming (peak memory ≈
|
|
7
|
-
* not the full file size), making this safe for large installers.
|
|
40
|
+
* Files are processed via streaming (peak memory ≈ the largest chunker `max` — 32 KB by default —
|
|
41
|
+
* per chunk, not the full file size), making this safe for large installers.
|
|
8
42
|
*
|
|
9
43
|
* - If `outFile` is omitted: compressed blockmap is appended to `inFile`
|
|
10
44
|
* (used for NSIS web installer / AppImage embed); `blockMapSize` is returned.
|
|
11
45
|
* - If `outFile` is provided: compressed blockmap is written to that file;
|
|
12
46
|
* `blockMapSize` is not included in the result.
|
|
13
47
|
*
|
|
48
|
+
* `options.regions` lets byte ranges of the input be chunked with their own parameters (see
|
|
49
|
+
* `BuildBlockMapOptions`). Chunk boundaries are forced at both edges of every region and the chunker
|
|
50
|
+
* state is reset there, so the blocks of a region depend only on the region's own bytes. Without
|
|
51
|
+
* regions the output is exactly what the default chunker produces. Regions never affect the returned
|
|
52
|
+
* `size` or `sha512`.
|
|
53
|
+
*
|
|
14
54
|
* Returned `sha512` is SHA-512 of the full file as it exists after the call.
|
|
15
55
|
*/
|
|
16
|
-
export declare function buildBlockMap(inFile: string, compressionFormat: CompressionFormat, outFile?: string): Promise<BlockMapDataHolder>;
|
|
56
|
+
export declare function buildBlockMap(inFile: string, compressionFormat: CompressionFormat, outFile?: string, options?: BuildBlockMapOptions): Promise<BlockMapDataHolder>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CHUNKER = void 0;
|
|
3
4
|
exports.buildBlockMap = buildBlockMap;
|
|
4
5
|
const crypto_1 = require("crypto");
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
7
|
const promises_1 = require("fs/promises");
|
|
7
8
|
const zlib = require("zlib");
|
|
8
|
-
const
|
|
9
|
+
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
9
10
|
// Rabin fingerprinting constants from github.com/aclements/go-rabin:
|
|
10
11
|
// Poly64 = 0xbfe6b8a5bf378d83 (degree-63 irreducible polynomial over GF(2))
|
|
11
12
|
// Window = 64 bytes, Avg = 16 KB, Min = 8 KB, Max = 32 KB
|
|
@@ -30,36 +31,121 @@ const RABIN_MAX = 32768;
|
|
|
30
31
|
const RABIN_WINDOW = 64;
|
|
31
32
|
// Boundary: all mask bits (14 bits) set in lo word. RABIN_AVG is a power of 2.
|
|
32
33
|
const RABIN_HASH_MASK = RABIN_AVG - 1; // 0x3FFF
|
|
34
|
+
/** Default chunker (go-rabin defaults): 8 KB min / 16 KB avg / 32 KB max. */
|
|
35
|
+
exports.DEFAULT_CHUNKER = { min: RABIN_MIN, avg: RABIN_AVG, max: RABIN_MAX };
|
|
33
36
|
function compress(data, format) {
|
|
34
37
|
return format === "deflate" ? zlib.deflateRawSync(data, { level: 9 }) : zlib.gzipSync(data, { level: 9 });
|
|
35
38
|
}
|
|
39
|
+
// The boundary test is `(lo & (avg - 1)) === avg - 1` on the low 32-bit word of the hash, so `avg`
|
|
40
|
+
// must fit in a 32-bit mask. 2^31 keeps the mask a non-negative int32.
|
|
41
|
+
const MAX_CHUNKER_AVG = 0x80000000;
|
|
42
|
+
function validateChunkerParams(where, chunker) {
|
|
43
|
+
if (chunker == null || typeof chunker !== "object") {
|
|
44
|
+
throw new Error(`${where}: chunker is required`);
|
|
45
|
+
}
|
|
46
|
+
const { min, avg, max } = chunker;
|
|
47
|
+
for (const [name, value] of [
|
|
48
|
+
["min", min],
|
|
49
|
+
["avg", avg],
|
|
50
|
+
["max", max],
|
|
51
|
+
]) {
|
|
52
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
53
|
+
throw new Error(`${where}: chunker.${name} must be a positive integer, got ${String(value)}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (avg > MAX_CHUNKER_AVG || (avg & (avg - 1)) !== 0) {
|
|
57
|
+
throw new Error(`${where}: chunker.avg must be a power of two not greater than ${MAX_CHUNKER_AVG}, got ${avg}`);
|
|
58
|
+
}
|
|
59
|
+
if (!(min < avg && avg <= max)) {
|
|
60
|
+
throw new Error(`${where}: chunker must satisfy min < avg <= max, got min=${min} avg=${avg} max=${max}`);
|
|
61
|
+
}
|
|
62
|
+
if (min <= RABIN_WINDOW) {
|
|
63
|
+
throw new Error(`${where}: chunker.min must be greater than the Rabin window (${RABIN_WINDOW}), got ${min}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate `regions` (ascending, non-overlapping, sane chunker parameters, within `fileSize`) and
|
|
68
|
+
* return a normalized copy.
|
|
69
|
+
*/
|
|
70
|
+
function normalizeRegions(regions, fileSize) {
|
|
71
|
+
const result = [];
|
|
72
|
+
let previousEnd = 0;
|
|
73
|
+
for (let i = 0; i < regions.length; i++) {
|
|
74
|
+
const region = regions[i];
|
|
75
|
+
const where = `blockmap region #${i}`;
|
|
76
|
+
if (region == null || typeof region !== "object") {
|
|
77
|
+
throw new Error(`${where}: must be an object with offset, size and chunker`);
|
|
78
|
+
}
|
|
79
|
+
const { offset, size } = region;
|
|
80
|
+
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
81
|
+
throw new Error(`${where}: offset must be a non-negative integer, got ${String(offset)}`);
|
|
82
|
+
}
|
|
83
|
+
if (!Number.isSafeInteger(size) || size <= 0) {
|
|
84
|
+
throw new Error(`${where}: size must be a positive integer, got ${String(size)}`);
|
|
85
|
+
}
|
|
86
|
+
validateChunkerParams(where, region.chunker);
|
|
87
|
+
if (offset < previousEnd) {
|
|
88
|
+
throw new Error(`${where}: regions must be ascending and non-overlapping (offset ${offset} < previous region end ${previousEnd})`);
|
|
89
|
+
}
|
|
90
|
+
const end = offset + size;
|
|
91
|
+
if (end > fileSize) {
|
|
92
|
+
throw new Error(`${where}: [${offset}, ${end}) extends past the end of the input (${fileSize} bytes)`);
|
|
93
|
+
}
|
|
94
|
+
previousEnd = end;
|
|
95
|
+
result.push({ offset, size, chunker: { min: region.chunker.min, avg: region.chunker.avg, max: region.chunker.max } });
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
36
99
|
/**
|
|
37
100
|
* Build a content-defined block map for `inFile` using Rabin fingerprinting.
|
|
38
101
|
*
|
|
39
|
-
* Files are processed via streaming (peak memory ≈
|
|
40
|
-
* not the full file size), making this safe for large installers.
|
|
102
|
+
* Files are processed via streaming (peak memory ≈ the largest chunker `max` — 32 KB by default —
|
|
103
|
+
* per chunk, not the full file size), making this safe for large installers.
|
|
41
104
|
*
|
|
42
105
|
* - If `outFile` is omitted: compressed blockmap is appended to `inFile`
|
|
43
106
|
* (used for NSIS web installer / AppImage embed); `blockMapSize` is returned.
|
|
44
107
|
* - If `outFile` is provided: compressed blockmap is written to that file;
|
|
45
108
|
* `blockMapSize` is not included in the result.
|
|
46
109
|
*
|
|
110
|
+
* `options.regions` lets byte ranges of the input be chunked with their own parameters (see
|
|
111
|
+
* `BuildBlockMapOptions`). Chunk boundaries are forced at both edges of every region and the chunker
|
|
112
|
+
* state is reset there, so the blocks of a region depend only on the region's own bytes. Without
|
|
113
|
+
* regions the output is exactly what the default chunker produces. Regions never affect the returned
|
|
114
|
+
* `size` or `sha512`.
|
|
115
|
+
*
|
|
47
116
|
* Returned `sha512` is SHA-512 of the full file as it exists after the call.
|
|
48
117
|
*/
|
|
49
|
-
async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
118
|
+
async function buildBlockMap(inFile, compressionFormat, outFile, options) {
|
|
119
|
+
const requestedRegions = options === null || options === void 0 ? void 0 : options.regions;
|
|
120
|
+
// The input is pre-stat'ed only when regions are given, so a region past the end of the file fails before any work is done.
|
|
121
|
+
const regions = requestedRegions == null || requestedRegions.length === 0 ? [] : normalizeRegions(requestedRegions, (await (0, promises_1.stat)(inFile)).size);
|
|
50
122
|
const fileHash = (0, crypto_1.createHash)("sha512");
|
|
51
123
|
const checksums = [];
|
|
52
124
|
const sizes = [];
|
|
53
125
|
let totalSize = 0;
|
|
54
|
-
//
|
|
55
|
-
|
|
126
|
+
// Chunker parameters of the current segment. A segment is either a region (its own parameters) or
|
|
127
|
+
// the span between regions (DEFAULT_CHUNKER). They only change when `filePos` crosses `segmentEnd`,
|
|
128
|
+
// so the per-byte loop never looks anything up.
|
|
129
|
+
let curMin = RABIN_MIN;
|
|
130
|
+
let curMax = RABIN_MAX;
|
|
131
|
+
let curMask = RABIN_HASH_MASK;
|
|
132
|
+
let curSkip = RABIN_MIN - RABIN_WINDOW;
|
|
133
|
+
let segmentEnd = Infinity; // absolute offset (exclusive) at which the current segment ends
|
|
134
|
+
let nextRegion = 0; // index into `regions` of the next region not yet entered
|
|
135
|
+
let filePos = 0; // absolute offset of the next byte fed to the chunker
|
|
136
|
+
// Per-chunk Rabin state. Peak memory ≈ largest `max` (RABIN_MAX = 32 KB by default) — not file size.
|
|
137
|
+
let maxChunkSize = RABIN_MAX;
|
|
138
|
+
for (const region of regions) {
|
|
139
|
+
maxChunkSize = Math.max(maxChunkSize, region.chunker.max);
|
|
140
|
+
}
|
|
141
|
+
const chunkBuf = Buffer.allocUnsafe(maxChunkSize);
|
|
56
142
|
let chunkN = 0; // bytes accumulated for current chunk
|
|
57
143
|
let hi = 0;
|
|
58
144
|
let lo = 0;
|
|
59
145
|
const win = new Uint8Array(RABIN_WINDOW); // rolling window ring buffer
|
|
60
146
|
let wpos = 0;
|
|
61
147
|
function emitChunk() {
|
|
62
|
-
checksums.push(Buffer.from((0,
|
|
148
|
+
checksums.push(Buffer.from((0, blake2_js_1.blake2b)(chunkBuf.subarray(0, chunkN), { dkLen: 18 })).toString("base64"));
|
|
63
149
|
sizes.push(chunkN);
|
|
64
150
|
chunkN = 0;
|
|
65
151
|
hi = 0;
|
|
@@ -67,15 +153,37 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
67
153
|
win.fill(0);
|
|
68
154
|
wpos = 0;
|
|
69
155
|
}
|
|
156
|
+
// Enter the segment that starts at absolute offset `pos` (always a forced chunk boundary, so the
|
|
157
|
+
// Rabin state is already reset here). Either the next region starts exactly at `pos`, or a
|
|
158
|
+
// default-chunker span runs from `pos` up to the next region (or to the end of the file).
|
|
159
|
+
function enterSegmentAt(pos) {
|
|
160
|
+
const region = nextRegion < regions.length ? regions[nextRegion] : null;
|
|
161
|
+
if (region != null && region.offset === pos) {
|
|
162
|
+
curMin = region.chunker.min;
|
|
163
|
+
curMax = region.chunker.max;
|
|
164
|
+
curMask = region.chunker.avg - 1;
|
|
165
|
+
curSkip = curMin - RABIN_WINDOW;
|
|
166
|
+
segmentEnd = region.offset + region.size;
|
|
167
|
+
nextRegion++;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
curMin = RABIN_MIN;
|
|
171
|
+
curMax = RABIN_MAX;
|
|
172
|
+
curMask = RABIN_HASH_MASK;
|
|
173
|
+
curSkip = RABIN_MIN - RABIN_WINDOW;
|
|
174
|
+
segmentEnd = region == null ? Infinity : region.offset;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
enterSegmentAt(0);
|
|
70
178
|
// Called once per byte; inlines the three-phase Rabin state machine:
|
|
71
179
|
// skip (< MIN-WINDOW bytes) → prime (next WINDOW bytes) → scan (≥ MIN bytes)
|
|
72
180
|
function processByte(b) {
|
|
73
181
|
chunkBuf[chunkN++] = b;
|
|
74
|
-
if (chunkN <=
|
|
182
|
+
if (chunkN <= curSkip) {
|
|
75
183
|
// Skip phase: not close enough to MIN to start priming yet
|
|
76
184
|
return;
|
|
77
185
|
}
|
|
78
|
-
if (chunkN <=
|
|
186
|
+
if (chunkN <= curMin) {
|
|
79
187
|
// Prime phase: non-windowed hash update, filling the ring buffer
|
|
80
188
|
win[wpos] = b;
|
|
81
189
|
wpos = (wpos + 1) % RABIN_WINDOW;
|
|
@@ -85,7 +193,7 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
85
193
|
hi = (nhi ^ PUSH_HI[top]) | 0;
|
|
86
194
|
lo = (nlo ^ PUSH_LO[top]) | 0;
|
|
87
195
|
// At exactly MIN: check whether the primed hash is already a boundary
|
|
88
|
-
if (chunkN ===
|
|
196
|
+
if (chunkN === curMin && (lo & curMask) === curMask) {
|
|
89
197
|
emitChunk();
|
|
90
198
|
}
|
|
91
199
|
return;
|
|
@@ -101,7 +209,7 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
101
209
|
const nlo = ((lo << 8) | b) & 0xffffffff;
|
|
102
210
|
hi = (nhi ^ PUSH_HI[top]) | 0;
|
|
103
211
|
lo = (nlo ^ PUSH_LO[top]) | 0;
|
|
104
|
-
if ((lo &
|
|
212
|
+
if ((lo & curMask) === curMask || chunkN >= curMax) {
|
|
105
213
|
emitChunk();
|
|
106
214
|
}
|
|
107
215
|
}
|
|
@@ -110,17 +218,36 @@ async function buildBlockMap(inFile, compressionFormat, outFile) {
|
|
|
110
218
|
const rs = (0, fs_1.createReadStream)(inFile, { highWaterMark: 256 * 1024 });
|
|
111
219
|
rs.on("data", (chunk) => {
|
|
112
220
|
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
221
|
+
fileHash.update(buf);
|
|
222
|
+
totalSize += buf.length;
|
|
223
|
+
let i = 0;
|
|
224
|
+
while (i < buf.length) {
|
|
225
|
+
// Feed bytes up to the end of the buffer or of the current segment, whichever comes first;
|
|
226
|
+
// `segmentEnd` is Infinity once the last region is behind us.
|
|
227
|
+
const n = Math.min(buf.length - i, segmentEnd - filePos);
|
|
228
|
+
const stop = i + n;
|
|
229
|
+
for (; i < stop; i++) {
|
|
230
|
+
processByte(buf[i]);
|
|
231
|
+
}
|
|
232
|
+
filePos += n;
|
|
233
|
+
if (filePos === segmentEnd) {
|
|
234
|
+
// Forced boundary at a region edge: flush whatever is pending and switch parameters.
|
|
235
|
+
if (chunkN > 0) {
|
|
236
|
+
emitChunk();
|
|
237
|
+
}
|
|
238
|
+
enterSegmentAt(filePos);
|
|
239
|
+
}
|
|
118
240
|
}
|
|
119
241
|
});
|
|
120
242
|
rs.on("end", () => {
|
|
121
243
|
if (chunkN > 0) {
|
|
122
244
|
emitChunk();
|
|
123
245
|
}
|
|
246
|
+
if (nextRegion < regions.length || segmentEnd !== Infinity) {
|
|
247
|
+
// Only reachable if the file shrank between the pre-stat and the read.
|
|
248
|
+
reject(new Error(`blockmap region extends past the end of the input (${totalSize} bytes)`));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
124
251
|
resolve();
|
|
125
252
|
});
|
|
126
253
|
rs.on("error", reject);
|