-
-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Hi, i have the situation that i have zip in zip ... an cannot figure out how to unpack all of them recursively.
maybe someone can point me to the problem here:
const recursiveUnZip = async (folder: string, zipfiles: string[]) => {
return await Promise.allSettled(
zipfiles.map(
zipFile =>
new Promise<string>((resolve, reject) => {
const resolveFunc = resolve
const rejectFunc = reject
const zip = new StreamZip({
storeEntries: true,
file: `${folder}/${zipFile.replace(/ /g, ' ')}`,
})
zip.on('error', function(err) {
console.error('[ERROR]', err)
})
zip.on('ready', function() {
console.log('All entries read: ' + zip.entriesCount)
})
zip.on('entry', function(entry) {
const pathname = path.resolve(`./${folder}`, entry.name)
if (/\.\./.test(path.relative(`./${folder}`, pathname))) {
console.warn(
'[zip warn]: ignoring maliciously crafted paths in zip file:',
entry.name
)
return
}
if ('/' === entry.name[entry.name.length - 1]) {
console.log('[DIR]', entry.name)
return
}
zip.extract(
entry,
`${folder}/${entry.name}`,
async (err?: string, res?: number | undefined) => {
console.log('DEBUG zip file entry name', entry.name)
if (path.parse(entry.name).ext.includes('zip')) {
console.log('DEBUUG', path.parse(entry.name).base)
await recursiveUnZip(folder, [path.parse(entry.name).base])
}
if (err) {
rejectFunc(`error: ${err}`)
} else {
}
}
)
})
zip.close(() => resolveFunc('done'))
})
)
)
}
any help would be great!
nichtich
Metadata
Metadata
Assignees
Labels
No labels