-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Switch from
unzipper
to adm-zip
- Loading branch information
Showing
5 changed files
with
73 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import AdmZip from 'adm-zip'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { wLogger } from './logger'; | ||
|
||
export const unzipTosu = ( | ||
zipPath: string, | ||
extractPath: string | ||
): Promise<string> => | ||
new Promise((resolve, reject) => { | ||
const zip = new AdmZip(zipPath); | ||
|
||
zip.getEntries().some((entry) => { | ||
if (entry.entryName === 'tosu' || entry.entryName === 'tosu.exe') { | ||
const fileName = path.basename(entry.entryName); | ||
const { name, ext } = path.parse(fileName); | ||
const modifyName = path.join(extractPath, `${name}_new${ext}`); | ||
|
||
return fs.writeFile( | ||
modifyName, | ||
entry.getData(), | ||
{ flag: 'w' }, | ||
(err) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
return resolve(modifyName); | ||
} | ||
); | ||
} | ||
}); | ||
|
||
reject('No matching entry found in the zip file.'); | ||
}); | ||
|
||
export const unzip = (zipPath: string, extractPath: string): Promise<string> => | ||
new Promise((resolve, reject) => { | ||
if (!fs.existsSync(extractPath)) { | ||
fs.mkdirSync(extractPath); | ||
} | ||
|
||
const zip = new AdmZip(zipPath); | ||
|
||
try { | ||
// Extract all contents of the zip file to the specified destination | ||
zip.extractAllTo(extractPath, /*overwrite*/ true); | ||
resolve(extractPath); | ||
} catch (error) { | ||
wLogger.error((error as any).message); | ||
reject(error); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"unzipper": "^0.10.14", | ||
"@tosu/common": "workspace:*" | ||
} | ||
} |