kevva / download

Download and extract files
MIT License
1.28k stars 200 forks source link

download().then() appears to be called immediately #125

Closed NinjaManatee closed 7 years ago

NinjaManatee commented 7 years ago

I have code that is supposed download a ZIP file, extract it, then perform some post-processing on the extracted files. download(zipLocation, distributionDir, { extract: true }) .then(postProcess());

When I run my code, my postProcess method fails because the files do not exist. If I remove the then, the files download. If I remove the throw from my post-process that occurs when the files are not found, the files are downloaded.

Am I mistaken that postProcess should be called after the download is complete? If so, how should I change my code to get the desire effect?

I am using download 6.1.0.

kevva commented 7 years ago

It depends on how your postProcess function looks. Currently you are invoking it immediately causing it to run even if download isn't finished. It should look something like below:

download(zipLocation, distributionDir, {extract: true}).then(postProcess);
// or
download(zipLocation, distributionDir, {extract: true}).then(data => postProcess(data));
NinjaManatee commented 7 years ago

Stupid me. I put in extra parentheses. Thanks!