refactor: unzip gotStream directly

without saving as a zipfile
This commit is contained in:
MDLeom 2023-08-04 12:03:27 +00:00
parent 61b1f67060
commit c9617be450
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 7 additions and 15 deletions

View File

@ -5,8 +5,8 @@
"build": "node src/build.js"
},
"dependencies": {
"extract-zip": "^2.0.1",
"got": "^11.8.3"
"got": "^11.8.3",
"unzipper": "^0.10.14"
},
"engines": {
"node": ">= 14.15.0"

View File

@ -9,8 +9,8 @@
const { stream: gotStream } = require('got')
const got = require('got')
const unzip = require('extract-zip')
const { basename, join } = require('path')
const { Extract: unzip } = require('unzipper')
const { join } = require('path')
const { mkdir } = require('fs/promises')
const { createWriteStream } = require('fs')
const { pipeline } = require('stream/promises')
@ -45,7 +45,7 @@ const oisdFilters = {
const pipelineStatus = async (url) => {
try {
const svg = await got(url).text()
if (!svg.includes('passed')) throw new Error('last gitlab pipeline failed')
if (svg.includes('failed')) throw new Error('last gitlab pipeline failed')
} catch ({ message }) {
throw new Error(message)
}
@ -54,7 +54,6 @@ 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
@ -62,7 +61,7 @@ const dl = async (project) => {
try {
await pipeline(
gotStream(link),
createWriteStream(zipPath)
unzip({ path: rootPath })
)
await pipelineStatus(pipelineUrl)
} catch ({ message }) {
@ -79,7 +78,7 @@ const dl = async (project) => {
try {
await pipeline(
gotStream(mirrorLink),
createWriteStream(zipPath)
unzip({ path: publicPath })
)
} catch ({ message }) {
throw new Error(JSON.stringify({
@ -89,13 +88,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 oisdDl = async (link, filename) => {