MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / decompress

Function decompress

daemon/src/common/compress.ts:65–104  ·  view source on GitHub ↗
(
  zipPath: string,
  dest: string,
  fileCode?: string
)

Source from the content-addressed store, hash-verified

63}
64
65export 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

Callers 1

unzipMethod · 0.90

Calls 4

check7zipStatusFunction · 0.90
use7zipFunction · 0.85
tryUnzipFunction · 0.85
checkFileNameFunction · 0.70

Tested by

no test coverage detected