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;AACA,QAAI,QAAQ,QAAR,IAAoB,IAAxB,EAA8B;AAC5B,WAAK,MAAM,IAAX,IAAmB,QAAQ,QAA3B,EAAqC;AACnC,aAAK,IAAL,CAAU,OAAO,IAAI,EAArB;AACD;AACF;;AAED,QAAI;AACF,YAAM,yBAAK,iBAAL,EAAc,IAAd,EAAoB;AACxB,aAAK,QAAQ,UAAR,GAAqB,YAArB,GAAoC,KAAK,OAAL,CAAa,YAAb;AADjB,OAApB,EAEH,uBAAQ,OAFL,CAAN;AAGD,KAJD,CAKA,OAAO,CAAP,EAAU;AACR,UAAI,EAAE,IAAF,KAAW,QAAX,IAAuB,EAAE,MAAM,kBAAO,YAAP,CAAR,CAA3B,EAA0D;AACxD,cAAM,IAAI,KAAJ,CAAU,2BAA2B,YAAY,iBAAjD,CAAN;AACD,OAFD,MAGK;AACH,cAAM,CAAN;AACD;AACF;;AAED,WAAO,OAAP;AACD,G;;kBA3BW,O","sourcesContent":["import { path7za } from \"7zip-bin\"\nimport { debug7z, debug7zArgs, exec } from \"builder-util\"\nimport { exists, unlinkIfExists } from \"builder-util/out/fs\"\nimport { move } from \"fs-extra-p\"\nimport * as path from \"path\"\nimport { TmpDir } from \"temp-file\"\nimport { CompressionLevel } from \"../core\"\nimport { getLinuxToolsPath } from \"./tools\"\n\n/** @internal */\nexport async function tar(compression: CompressionLevel | any | any, format: string, outFile: string, dirToArchive: string, isMacApp: boolean, tempDirManager: TmpDir): Promise<void> {\n const tarFile = await tempDirManager.getTempFile({suffix: \".tar\"})\n const tarArgs = debug7zArgs(\"a\")\n tarArgs.push(tarFile)\n tarArgs.push(path.basename(dirToArchive))\n\n await Promise.all([\n exec(path7za, tarArgs, {cwd: path.dirname(dirToArchive)}),\n // remove file before - 7z doesn't overwrite file, but update\n unlinkIfExists(outFile),\n ])\n\n if (!isMacApp) {\n await exec(path7za, [\"rn\", tarFile, path.basename(dirToArchive), path.basename(outFile, `.${format}`)])\n }\n\n if (format === \"tar.lz\") {\n // noinspection SpellCheckingInspection\n let lzipPath = \"lzip\"\n if (process.platform === \"darwin\") {\n lzipPath = path.join(await getLinuxToolsPath(), \"bin\", lzipPath)\n }\n await exec(lzipPath, [compression === \"store\" ? \"-1\" : \"-9\", \"--keep\" /* keep (don't delete) input files */, tarFile])\n // bloody lzip creates file in the same dir where input file with postfix `.lz`, option --output doesn't work\n await move(`${tarFile}.lz`, outFile)\n return\n }\n\n const args = compute7zCompressArgs(format === \"tar.xz\" ? \"xz\" : (format === \"tar.bz2\" ? \"bzip2\" : \"gzip\"), {\n isRegularFile: true,\n method: \"DEFAULT\",\n compression,\n })\n args.push(outFile, tarFile)\n await exec(path7za, args, {\n cwd: path.dirname(dirToArchive),\n }, 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 listFile?: string\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\nexport function compute7zCompressArgs(format: string, options: ArchiveOptions = {}) {\n let storeOnly = options.compression === \"store\"\n const args = debug7zArgs(\"a\")\n\n let isLevelSet = false\n if (process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL != null) {\n storeOnly = false\n args.push(`-mx=${process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL}`)\n isLevelSet = true\n }\n\n const isZip = format === \"zip\"\n if (!storeOnly) {\n if (isZip && options.compression === \"maximum\") {\n // http://superuser.com/a/742034\n args.push(\"-mfb=258\", \"-mpass=15\")\n }\n\n if (!isLevelSet) {\n // https://github.com/electron-userland/electron-builder/pull/3032\n args.push(\"-mx=\" + ((!isZip || options.compression === \"maximum\") ? \"9\" : \"7\"))\n }\n }\n\n if (options.dictSize != null) {\n args.push(`-md=${options.dictSize}m`)\n }\n\n // https://sevenzip.osdn.jp/chm/cmdline/switches/method.htm#7Z\n // https://stackoverflow.com/questions/27136783/7zip-produces-different-output-from-identical-input\n // tc and ta are off by default, but to be sure, we explicitly set it to off\n // disable \"Stores NTFS timestamps for files: Modification time, Creation time, Last access time.\" to produce the same archive for the same data\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 // args valid only for 7z\n // -mtm=off disable \"Stores last Modified timestamps for files.\"\n args.push(\"-mtm=off\", \"-mta=off\")\n }\n\n if (options.method != null) {\n if (options.method !== \"DEFAULT\") {\n args.push(`-mm=${options.method}`)\n }\n }\n else if (isZip || storeOnly) {\n args.push(`-mm=${storeOnly ? \"Copy\" : \"Deflate\"}`)\n }\n\n if (isZip) {\n // -mcu switch: 7-Zip uses UTF-8, if there are non-ASCII symbols.\n // because default mode: 7-Zip uses UTF-8, if the local code page doesn't contain required symbols.\n // but archive should be the same regardless where produced\n args.push(\"-mcu\")\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 args = compute7zCompressArgs(format, options)\n // remove file before - 7z doesn't overwrite file, but update\n await unlinkIfExists(outFile)\n\n args.push(outFile, options.listFile == null ? (options.withoutDir ? \".\" : path.basename(dirToArchive)) : `@${options.listFile}`)\n if (options.excluded != null) {\n for (const mask of options.excluded) {\n args.push(`-xr!${mask}`)\n }\n }\n\n try {\n await exec(path7za, args, {\n cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive),\n }, debug7z.enabled)\n }\n catch (e) {\n if (e.code === \"ENOENT\" && !(await exists(dirToArchive))) {\n throw new Error(`Cannot create archive: \"${dirToArchive}\" doesn't exist`)\n }\n else {\n throw e\n }\n }\n\n return outFile\n}"],"sourceRoot":""}