Skip to content

Commit 43dd3f0

Browse files
authored
Merge pull request #74 from njhale/enhance/cleanup
enhance: cleanup zip/tar files after extracting gptscript binary
2 parents d56f122 + 6bb5fe0 commit 43dd3f0

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

package-lock.json

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/install-binary.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ async function downloadAndExtract(url, saveDirectory) {
1717

1818
return new Promise((resolve, reject) => {
1919
dlh.on('end', () => {
20+
const downloadedFilePath = path.join(dlh.getDownloadPath());
2021
if (url.endsWith('.zip')) {
21-
const zip = new AdmZip(path.join(dlh.getDownloadPath()));
22+
const zip = new AdmZip(downloadedFilePath);
2223
zip.extractAllTo(saveDirectory, true);
24+
fs.unlinkSync(downloadedFilePath);
2325
} else if (url.endsWith('.tar.gz')) {
2426
tar.x({
25-
file: path.join(dlh.getDownloadPath()),
27+
file: downloadedFilePath,
2628
cwd: saveDirectory,
27-
});
29+
}).then(() => {
30+
fs.unlinkSync(downloadedFilePath); // Delete the tar.gz file after extraction
31+
}).catch((error) => reject(error));
2832
}
2933
resolve();
3034
});
@@ -121,10 +125,8 @@ async function needToInstall() {
121125

122126
console.log(`Downloading and extracting gptscript binary from ${url}...`);
123127
try {
124-
downloadAndExtract(url, outputDir)
128+
await downloadAndExtract(url, outputDir);
125129
} catch (error) {
126-
console.error('Error downloading and extracting:', error)
130+
console.error('Error downloading and extracting:', error);
127131
}
128132
})();
129-
130-

0 commit comments

Comments
 (0)