From 499330a12d93cb30c5771354316ddade260ebfdc Mon Sep 17 00:00:00 2001 From: MDLeom <2809763-curben@users.noreply.gitlab.com> Date: Sun, 27 Oct 2024 05:18:07 +0000 Subject: [PATCH] build: extract zip from stream previous bug should be fixed in recent node versions b03e462e421486e31ee92a495fdae42ec36a160d https://github.com/ZJONSSON/node-unzipper/issues/271#issuecomment-2021223739 --- package.json | 2 +- src/build.js | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index a8b28b1..e1f343b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "build": "node src/build.js" }, "dependencies": { - "extract-zip": "^2.0.1" + "unzipper": "^0.12.3" }, "engines": { "node": ">= 18.12.0" diff --git a/src/build.js b/src/build.js index 3bc7034..10ef371 100644 --- a/src/build.js +++ b/src/build.js @@ -7,10 +7,9 @@ // Instead of using the API, I find it easier to failover to GitHub. // ref: https://gitlab.com/gitlab-org/gitlab/-/issues/29257 -import unzip from 'extract-zip' -import { basename, dirname, join } from 'node:path' +import { Extract } from 'unzipper' +import { dirname, join } from 'node:path' import { mkdir, readdir, rm } from 'node:fs/promises' -import { createWriteStream } from 'node:fs' import { pipeline } from 'node:stream/promises' import { fileURLToPath } from 'node:url' import { Readable } from 'node:stream' @@ -24,7 +23,7 @@ const projects = [ 'phishing-filter', 'tracking-filter', 'vn-badsite-filter', - 'botnet-filter', + 'botnet-filter' // 'pup-filter' ] @@ -41,15 +40,13 @@ const pipelineStatus = async (url) => { const dl = async (project) => { const filename = project + '.zip' const link = `https://gitlab.com/malware-filter/${project}/-/jobs/artifacts/main/download?job=pages` - const zipPath = join(tmpPath, filename) const pipelineUrl = `https://gitlab.com/malware-filter/${project}/badges/main/pipeline.svg` - let isMirror = false console.log(`Downloading ${filename} from "${link}"`) try { await pipeline( Readable.fromWeb((await fetch(link)).body), - createWriteStream(zipPath) + Extract({ path: rootPath }) ) await pipelineStatus(pipelineUrl) } catch ({ message }) { @@ -61,12 +58,11 @@ const dl = async (project) => { const mirrorLink = `https://nightly.link/curbengh/${project}/workflows/pages/main/public.zip` console.log(`Downloading ${filename} from "${mirrorLink}"`) - isMirror = true try { await pipeline( Readable.fromWeb((await fetch(mirrorLink)).body), - createWriteStream(zipPath) + Extract({ path: publicPath }) ) } catch ({ message }) { throw new Error(JSON.stringify({ @@ -76,13 +72,6 @@ const dl = async (project) => { })) } } - - console.log(`Extracting ${basename(zipPath)}...`) - if (isMirror === false) { - await unzip(zipPath, { dir: rootPath }) - } else { - await unzip(zipPath, { dir: publicPath }) - } } const f = async () => {