Skip to content

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

@anandncode

Description

@anandncode

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions