Skip to content

Files extracted from zip are currupt #271

Description

@webwake

The extracted files are getting corrupts, this started to happen after upgrading from Node 18 to Node.js 19.8.1 on Windows 10 (haven't tested if broader issue)

Below is a code sample to reproduce the issue. Have incorporated the decompress library to demonstrate an non-corrupt file

const fs = require('fs');
const unzipper = require('unzipper');
const { https } = require('follow-redirects');
const crypto = require("crypto");

const decompress = require('decompress');

async function downloadBinariesFromRelease() {
    await new Promise((resolve, reject) => {
        fs.mkdirSync('unzipper', { recursive: true });
        const file = fs.createWriteStream('binaries.zip');
        console.log('Downloading Neutralinojs binaries..');
        https.get("https://github.com/neutralinojs/neutralinojs/releases/download/v4.10.0/neutralinojs-v4.10.0.zip", function (response) {
            response.pipe(file);
            response.on('end', () => {
                resolve();
            });
        });
    });
}

function fileHash(filename, algorithm = 'md5') {
    return new Promise((resolve, reject) => {
        // Algorithm depends on availability of OpenSSL on platform
        // Another algorithms: 'sha1', 'md5', 'sha256', 'sha512' ...
        let shasum = crypto.createHash(algorithm);
        try {
            let s = fs.ReadStream(filename)
            s.on('data', function (data) {
                shasum.update(data)
            })
            // making digest
            s.on('end', function () {
                const hash = shasum.digest('hex')
                return resolve(hash);
            })
        } catch (error) {
            return reject('calc fail');
        }
    });
}

async function extractWithUnzipperLibrary() {
    await new Promise((resolve, reject) => {
        console.log('Extracting using "unzipper" library')
        fs.createReadStream('binaries.zip')
            .pipe(unzipper.Extract({ path: './unzipper' }))
            .promise()
            .then(() => resolve())
            .catch((e) => reject(e));
    });
}

async function extractWithDecompressLibrary() {
    console.log('Extracting using "decompress" library')
    await decompress('binaries.zip', 'decompress');
}


async function main() {
    await downloadBinariesFromRelease();
    await extractWithUnzipperLibrary();
    await extractWithDecompressLibrary();
    

    console.log(`correct hash:    3bbb562a59a454534f0ced6c801ccdb7`);
    console.log(`unzipper hash:   ${await fileHash("unzipper/neutralino-win_x64.exe", "md5")}`);
    console.log(`decompress hash: ${await fileHash("decompress/neutralino-win_x64.exe", "md5")}`);
}

main();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions