Revert "refactor: unzip gotStream directly"

- extracted files are missing first few lines
This reverts commit c9617be450.
This commit is contained in:
MDLeom 2023-08-06 11:16:26 +00:00
parent 3b13737e91
commit b03e462e42
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
2 changed files with 15 additions and 7 deletions

View File

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

View File

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