ibrod83 / nodejs-file-downloader

129 stars 23 forks source link

Absolute `fileName` path not working on windows #32

Open ihm-tswow opened 2 years ago

ihm-tswow commented 2 years ago

Trying to set fileName to an absolute path on windows stacks it on top of the working directory.

How we use it:

import * as Downloader from 'nodejs-file-downloader';

...
    await new Downloader.default(
        {
            url
            , fileName: resfp(file)
            , cloneFiles: false
            , maxAttempts: 3
        }
    ).download();

For a run where resfp(file) resolves to C:\tswow-build-2\cmake-3.18.3-win64-x64.zip and working directory is D:\dev\wow\tswow\, I get the following error:

ENOENT: no such file or directory, unlink 'D:\dev\wow\tswow\C:\tswow-build-2\cmake-3.18.3-win64-x64.zip.download'

ihm-tswow commented 2 years ago

Solution is of course

    directory: path.dirname(file),
    fileName: path.basename(file),
xmsz-stu commented 8 months ago

i get this one

ENOENT: no such file or directory, unlink 'C:\Windows\System32\360safemon.dll.download'
ibrod83 commented 8 months ago

i get this one

ENOENT: no such file or directory, unlink 'C:\Windows\System32360safemon.dll.download'

Did you try setting the "directory" attribute separately? Note that "fileName" refers to the name of the file itself, not the entire path

xmsz-stu commented 8 months ago

i get this one

ENOENT: no such file or directory, unlink 'C:\Windows\System32360safemon.dll.download'

Did you try setting the "directory" attribute separately? Note that "fileName" refers to the name of the file itself, not the entire path

my code

const downloader = new Downloader({
    url: '****',
    directory: path.join('C:', 'Windows', 'System32'),
    onBeforeSave: (deducedName) => '360safemon.dll',
  });
  const res = await downloader.download();
ibrod83 commented 8 months ago

i get this one

ENOENT: no such file or directory, unlink 'C:\Windows\System32360safemon.dll.download'

Did you try setting the "directory" attribute separately? Note that "fileName" refers to the name of the file itself, not the entire path

my code

const downloader = new Downloader({
    url: '****',
    directory: path.join('C:', 'Windows', 'System32'),
    onBeforeSave: (deducedName) => '360safemon.dll',
  });
  const res = await downloader.download();

you're getting this error due to permissions issue. windows doesn't allow free access to this directory. My error handling in this procedure just swallows the original error, which made it unclear:

'EPERM: operation not permitted, open 'C:\Windows\System32\360safemon.dll.download''

xmsz-stu commented 8 months ago

i get this one

ENOENT: no such file or directory, unlink 'C:\Windows\System32360safemon.dll.download'

Did you try setting the "directory" attribute separately? Note that "fileName" refers to the name of the file itself, not the entire path

my code

const downloader = new Downloader({
    url: '****',
    directory: path.join('C:', 'Windows', 'System32'),
    onBeforeSave: (deducedName) => '360safemon.dll',
  });
  const res = await downloader.download();

you're getting this error due to permissions issue. windows doesn't allow free access to this directory. My error handling in this procedure just swallows the original error, which made it unclear:

'EPERM: operation not permitted, open 'C:\Windows\System32\360safemon.dll.download''

ok, thanks