ibrod83 / nodejs-file-downloader

130 stars 23 forks source link

skipExistingFileName ingored #20

Closed bbo2adwuff closed 3 years ago

bbo2adwuff commented 3 years ago

Even when setting skipExistingFileName file gets downloaded if file with same name present in directory.

How to reproduce

  1. Run code below
  2. Check if file ./downloads/200MB.zip exists.
  3. Run code second time
  4. ./downloads/200MB_2.zip exists.
const Downloader = require('nodejs-file-downloader');

(async () => {//Wrapping the code with an async function, just for the sake of example.

    const downloader = new Downloader({
      url: 'http://212.183.159.230/200MB.zip',//If the file name already exists, a new file with the name 200MB1.zip is created.     
      directory: "./downloads",//This folder will be created, if it doesn't exist.         
      skipExistingFileName: true,      
    })
    try {
      await downloader.download();//Downloader.download() returns a promise.

      console.log('All done');
    } catch (error) {//IMPORTANT: Handle a possible error. An error is thrown in case of network errors, or status codes of 400 and above.
      //Note that if the maxAttempts is set to higher than 1, the error is thrown only if all attempts fail.
      console.log('Download failed',error)
    }

})();    

Expected behavior

./downloads/200MB_2.zip shouldn't exist.

Version

nodejs-file-downloader 4.7.2 node --version v16.6.0 Archlinux 5.13.7

bbo2adwuff commented 3 years ago

Ah I just gave it a try with:

        cloneFiles: false,
        skipExistingFileName: true,

Then it works. Okay I didn't expect that.

I'll just leave this issue open and it's up to you to close it. IMHO get skipExistingFileName working without cloneFiles feels more intuitive or at least mentioning it in the readme.md would help.

ibrod83 commented 3 years ago

Thank you for your input. I'll look into it

ibrod83 commented 3 years ago

fixed in 4.7.4