kevva / download

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

Option to skip downloading if the file already exists #211

Open aminya opened 3 years ago

naomi443 commented 3 years ago

Great idea

Edim7 commented 3 years ago

I think such feature might just work better implemented on your own. A simple way would be to use fs.existsSync( path + filename) to check if the file already exists presuming your name has the version of the file in question.

naomi443 commented 3 years ago

Sorry hon, I still have no idea what you are talking about?

On Sat., 17 Apr. 2021, 06:20 Edim, @.***> wrote:

I think such feature might just work better implemented on your own. A simple way would be to use fs.existsSync( path + filename) to check if the file already exists presuming your name has the version of the file in question.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kevva/download/issues/211#issuecomment-821539182, or unsubscribe https://github.com/notifications/unsubscribe-auth/APMWEOCCAZJUFU6UU2W4IQLTJCL2NANCNFSM4UR7KCVA .

aminya commented 3 years ago

Ideally, I want an option that optionally can accept a function used for version checking.

Passing a boolean:

download(url, destination, { skipReDownload: true})

Passing a function that returns a boolean:

download(url, destination, { skipReDownload: versionCheckFunction})

function versionCheckFunction(path_to_file: string) {
    // do any version check that you want to do here and return a boolean

    return true // skip redownload
    return false // the file is old -> redownload
}
naomi443 commented 3 years ago

You may aswell be talking Double Dutch to me. Not a developer. 🙄🙄ðŸĪ”ðŸĪŠ

On Sat., 17 Apr. 2021, 17:12 Amin Yahyaabadi, @.***> wrote:

Ideally, I want an option that optionally can accept a function used for version checking.

Default:

download(url, destination, { skipReDownload: true})

With a function

download(url, destination, { skipReDownload: versionCheckFunction}) function versionCheckFunction(path_to_file) { // do any version control that you want to do here and return a boolean // return true // skip redownload return false // the file is old -> redownload}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kevva/download/issues/211#issuecomment-821780404, or unsubscribe https://github.com/notifications/unsubscribe-auth/APMWEOCPDRYZCTNGQV5AFFDTJEYHJANCNFSM4UR7KCVA .

Edim7 commented 3 years ago

Ideally, I want an option that optionally can accept a function used for version checking.

Passing a boolean:

download(url, destination, { skipReDownload: true})

Passing a function that returns a boolean:

download(url, destination, { skipReDownload: versionCheckFunction})

function versionCheckFunction(path_to_file: string) {
  // do any version check that you want to do here and return a boolean

  return true // skip redownload
  return false // the file is old -> redownload
}

Yeah that was my point, if you were to create your own version check function what stops you from doing an if statement and checking for the status of the custom function, and then decide if you are going to run the download or not? Based on that if you can provide output that will signify that the exact same version already exists locally.

aminya commented 3 years ago

The version check is optional and only for those who need extra flexibility (which you should always consider when designing an interface). For my personal use, I am happy to just pass true to skipReDownload.