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

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

Open
GoldFrite opened this issue Jul 25, 2021 · 11 comments

Comments

@GoldFrite
Copy link

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.

@ibrod83
Copy link
Owner

ibrod83 commented Jul 25, 2021

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

@GoldFrite
Copy link
Author

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
Copy link
Author

I have also a very bad conection:
image

@ibrod83
Copy link
Owner

ibrod83 commented Jul 25, 2021

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
Copy link
Owner

ibrod83 commented Jul 25, 2021

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

@GoldFrite
Copy link
Author

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".

@ibrod83
Copy link
Owner

ibrod83 commented Jul 26, 2021

:D

@ibrod83 ibrod83 closed this as completed Jul 26, 2021
@GoldFrite
Copy link
Author

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

@ibrod83 ibrod83 reopened this Jul 26, 2021
@ibrod83
Copy link
Owner

ibrod83 commented Jul 26, 2021

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

@GoldFrite
Copy link
Author

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.

@ibrod83
Copy link
Owner

ibrod83 commented Jul 27, 2021

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.

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

2 participants