From 53ec052a030b99eae1e81de67d6d97e137a979d8 Mon Sep 17 00:00:00 2001 From: Moe Date: Thu, 12 Sep 2024 09:33:59 -0700 Subject: [PATCH] replace adm-zip with unzipper in cmd plugin downloader --- tools/downloadPlugins.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/downloadPlugins.js b/tools/downloadPlugins.js index 616a5683..3183513c 100644 --- a/tools/downloadPlugins.js +++ b/tools/downloadPlugins.js @@ -1,5 +1,5 @@ const fetch = require('node-fetch'); -const AdmZip = require('adm-zip'); +const unzipper = require('unzipper'); const fs = require('fs').promises; const path = require('path'); @@ -21,13 +21,14 @@ async function fetchAndDownloadFolder(folderName) { throw new Error(`Failed to download folder: ${response.statusText}`); } - const buffer = await response.buffer(); - const zip = new AdmZip(buffer); - - // Extract the ZIP to a temporary location + // Create a temporary path for extraction const tempExtractPath = path.join(process.cwd(), 'temp_extracted'); await fs.mkdir(tempExtractPath, { recursive: true }); - zip.extractAllTo(tempExtractPath, true); + + // Extract the ZIP using unzipper + await response.body + .pipe(unzipper.Extract({ path: tempExtractPath })) + .promise(); // Find the folder ending with the target name const extractedFolder = (await fs.readdir(tempExtractPath)).find(dir => dir.endsWith(folderName)); @@ -66,3 +67,5 @@ if (!folderName) { console.error('Usage: node script.js '); process.exit(1); } + +fetchAndDownloadFolder(folderName);