Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip-stream exits abruptly without any error if content is large #109

Open
anandncode opened this issue Jan 13, 2022 · 5 comments
Open

zip-stream exits abruptly without any error if content is large #109

anandncode opened this issue Jan 13, 2022 · 5 comments

Comments

@anandncode
Copy link

anandncode commented Jan 13, 2022

Description

When trying to add a string of considerable size such as >7 MB, the archive.entry exits abruptly without any exception and exit code - 0.

Below is sample code

const ZipStream = require('zip-stream');
const archive = new ZipStream(); 

function arrayToCsv(dataArray) {
    const output = dataArray.map((val) => {
        if (val === null || val === undefined) {
            return '';
        }
        const modVal = `${val}`; // Convert everything to string
        return `"${modVal.replace(/"/g, '""')}"`;
    }).join(separator);
    return output;
}

function getCSV(rows, cols = 10) {

    let csv = '';
    for (let i = 0; i < rows; i++) { // files

        const row = new Array(cols);
        row.fill(`randomString${i + 1}`);
        csv = csv + arrayToCsv(row) + '\n';
    }
    return csv;
}

process.on('exit', (code) => {
    console.log(`Process exit with code - ${code}`)
});

console.log(`Before adding csv`);
csv = getCSV(20000);

archive.entry(csv, { name: 'csv1.csv', zlib: { level: 9 } }, (err, entry) => {
    if (err) {
        throw err
    }
    console.log(`After adding csv`);
    archive.finish();
})

Output

Before adding csv
Process exit with code 0

The After adding csv is not printed to console.

I have used object-sizeof to calculate size of csv
size of csv - 7777880 OR 7.42 MB

For lower sizes, it works fine.

Please let me know if there is anything wrong with the code above.

@anandncode anandncode changed the title zip-stream exits abruptly zip-stream exits abruptly without any error if content is large Jan 13, 2022
@anandncode
Copy link
Author

anandncode commented Jan 13, 2022

Btw the same thing works fine with archiver. Also calling zlib.deflate on csv string also works fine without any issue

@littlemaneuver
Copy link

tested your example, seems like it is due to the stream buffer overflow if you don't read the zip stream then it is silently killed

@anandncode
Copy link
Author

Thanks @antoniopuero
Shouldn't it throw an error and call the callback? Also, 7.4 MB shouldn't be a big size as most of the zip scenarios deal with large file sizes.

@benjaminben
Copy link

@anandncode were you ever able to resolve this? Seeing the same issue with a much smaller total file size (< 1mb) but a large number of files

@anandncode
Copy link
Author

@benjaminben I could vaguely remember that I changed the library to fflate and it worked better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants