nodejs-file-downloader icon indicating copy to clipboard operation
nodejs-file-downloader copied to clipboard

"Uncaught (in promise) Error: end of central directory record signature not found" when trying to open or extract after download

Open GoldFrite opened this issue 4 years ago • 11 comments

Hello, I am trying to download a ZIP file with nodejs-file-downloader. But when I try to extract the file, I get the following error:

Uncaught (in promise) Error: end of central directory record signature not found

I think the problem is with nodejs-file-downloader because when I download the file with this module, the file is 72.1 MB, but when I download the file with Chrome, the file is 75.2 MB. I can't open the ZIP file downloaded with this module with Windows File Explorer, but I can do it with 7zip. When I open the 75.2 MB ZIP file, there are 3 folders and 8 files. When I open the 72.1 MB ZIP file, there are 3 folders but 2 files (and the 3rd folder is smaller than in the 75.2 MB file).

The error message is not coming from the nodejs-file-downloader module, but from another one, but I think it is a problem with the nodejs-file-downloader module. Thanks for your help.

GoldFrite avatar Jul 25 '21 19:07 GoldFrite

Can you show some code? Also, what node version and what OS?

ibrod83 avatar Jul 25 '21 19:07 ibrod83

Thanks for your answer! My PC is running Windows 11, and I have NodeJS 14.16.1. My code:

async function changeDlJava() {
    const jreDownloader = new Downloader({
        url: "https://www.dropbox.com/s/262kaub0ra1ma3d/java.zip?dl=1", // This link work!
        directory: "C:/Users/GoldFrite/AppDara/Roaming/" + gameFileName + "/runtime/",
        fileName: "JRE.zip",
        cloneFiles: false,
        onProgress: function (percentage) {
            progressBar.max = "100"
            progressBar.value = percentage
        }
    })
    try {
        await jreDownloader.download()
            .then(() => {
                    try {
                        decompress("C:/Users/GoldFrite/AppDara/Roaming" + gameFileName + "/runtime/JRE.zip", "C:/Users/GoldFrite/AppDara/Roaming" + gameFileName + "/runtime/") // With 'decompress' module
                            .then(() => {
                                try {
                                    fs.unlink("C:/Users/GoldFrite/AppDara/Roaming/" + gameFileName + "/runtime/JRE.zip", () => { })

                                    /* Others actions */

                                } catch (err) {
                                    console.error(err);
                                }
                            })
                    } catch (err) {
                            console.error(err);
                        }
                    }
                }
            })
    } catch (err) {
            console.error(err);
        }
    }
}

GoldFrite avatar Jul 25 '21 20:07 GoldFrite

I have also a very bad conection: image

GoldFrite avatar Jul 25 '21 20:07 GoldFrite

Well, i've tried downloading and decompressing this file sevral times, and it always works. The size of the zip is: 78,908,207. size of the decompressed folder: 213,470,604. I dont know why in your case the file is incomplete. Try getting rid of the "callback hell"(clean up the code with async await. you can also used a promisified version of fs.unlink). Then, would be eaiser for you to debug. Also note that putting then() after await doesn't make sense(though it seems to work :D).

ibrod83 avatar Jul 25 '21 21:07 ibrod83

ah lol and notice you wrote appDara instead of appData :D

ibrod83 avatar Jul 25 '21 21:07 ibrod83

Well, i've tried downloading and decompressing this file sevral times, and it always works. The size of the zip is: 78,908,207. size of the decompressed folder: 213,470,604.

Ok, I think the problem is with my connection...

Try getting rid of the "callback hell"(clean up the code with async await. you can also used a promisified version of fs.unlink).

Ok!

ah lol and notice you wrote appDara instead of appData :D

😂 No, in fact, this is not my real code: instead of the full link ("C:/Users/GoldFrite/AppDara/Roaming" + gameFileName + "/runtime/JRE.zip"), I use variables, like appData + gameFileName + "/runtime/JRE.zip".

GoldFrite avatar Jul 26 '21 13:07 GoldFrite

:D

ibrod83 avatar Jul 26 '21 15:07 ibrod83

Ok so I don't understand why, but I've retried now without any changing and it works... My connection?

GoldFrite avatar Jul 26 '21 16:07 GoldFrite

the cnnection of course can cause problems. BUT, it should eventually trigger some exception.

ibrod83 avatar Jul 26 '21 16:07 ibrod83

Yes. I don't understand. But now it works. Maybe the connection was so low that the module thought the download was complete, but in fact it is missing a few bytes.

GoldFrite avatar Jul 27 '21 09:07 GoldFrite

I will need to explore this. my tests do not cover a scenario of lost connection, or anything like it. they cover many error scenarious though. i'll add some tests later on.

ibrod83 avatar Jul 27 '21 16:07 ibrod83