antelle / node-stream-zip

node.js library for fast reading of large ZIPs
Other
447 stars 63 forks source link

unzip files with spaces in filename? #100

Open pcace opened 1 year ago

pcace commented 1 year ago

Hi,

is it possible that i get this error:

DEBUG zip file entry name Mossautal - LoD2.zip
[ERROR] Error: Bad archive
    at FsRead.readUntilFoundCallback [as callback] (/home/user/git/FFYselfservingAPI/node_modules/node-stream-zip/node_stream_zip.js:198:39)
    at FsRead.readCallback (/home/user/git/FFYselfservingAPI/node_modules/node-stream-zip/node_stream_zip.js:996:25)
    at FSReqCallback.wrapper [as oncomplete] (node:fs:682:5)

because of the spaces in the filename? how can i get more information of what is actually failing here? i am running node 18.15.0

this is the code im am using:

    for (const zipFile of filteredPath) {
        await new Promise<string>((resolve, reject) => {
            dzip = new StreamZip({ storeEntries: true, file: `${folder}/${zipFile}` })
            dzip.on('error', function(err) {
                console.error('[ERROR] dzip on ', err)
            })
            dzip.on('ready', function() {
                console.log(getCurrentTime(), 'All entries read: ' + dzip.entriesCount)
                // console.log(getCurrentTime(),zip.entries());
            })
            dzip.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(getCurrentTime(), '[DIR]', entry.name)
                    return
                }

                dzip.extract(
                    entry,
                    `${folder}/${entry.name}`,
                    (err?: string, res?: number | undefined) => {
                        console.log('DEBUG zip file entry name', entry.name)

                        resolve(entry.name)
                    }
                )
            })
        })
    }

any help would be awesome!