( zipPath: string, dest: string, fileCode?: string )
| 63 | } |
| 64 | |
| 65 | export async function decompress( |
| 66 | zipPath: string, |
| 67 | dest: string, |
| 68 | fileCode?: string |
| 69 | ): Promise<boolean> { |
| 70 | if (!checkFileName(zipPath) || !checkFileName(dest)) |
| 71 | throw new Error(COMPRESS_ERROR_MSG.invalidName); |
| 72 | |
| 73 | const tryUnzip = async () => { |
| 74 | if (!isZipFormat(zipPath)) { |
| 75 | const fileExt = getFileExtension(zipPath); |
| 76 | throw new Error($t("TXT_CODE_69c42450", { fileExt: fileExt })); |
| 77 | } |
| 78 | |
| 79 | if (isMultiVolume(zipPath)) { |
| 80 | throw new Error($t("TXT_CODE_91d066aa")); |
| 81 | } |
| 82 | try { |
| 83 | return await useUnzip(zipPath, dest, fileCode || "utf-8"); |
| 84 | } catch (error: any) { |
| 85 | logger.error($t("TXT_CODE_842929d0", { message: error.message })); |
| 86 | throw new Error( |
| 87 | $t("TXT_CODE_f0512848", { |
| 88 | message: error?.message |
| 89 | }) |
| 90 | ); |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | if (await check7zipStatus()) { |
| 95 | try { |
| 96 | return await use7zip(zipPath, dest); |
| 97 | } catch (error) { |
| 98 | // if 7zip is not working, try to use unzip |
| 99 | return await tryUnzip(); |
| 100 | } |
| 101 | } else { |
| 102 | return await tryUnzip(); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Decompress using 7zip |
no test coverage detected