hgouveia / node-downloader-helper

A simple http file downloader for node.js
MIT License
247 stars 54 forks source link

Filename unexpectedly changed after download #58

Closed TAINCER closed 2 years ago

TAINCER commented 3 years ago

When downloading a file with a dot prefix the actual file that is saved doesn't include the dot. Is there a way to disable this behavior? For my case, I need 1:1 the file names from the server on the local Disc.

Demo Code:

const { DownloaderHelper } = require('node-downloader-helper');

const dl = new DownloaderHelper(
    'https://files.taincer.com/testdata/.changelog.txt',
    __dirname,
    {
        override: true,
        fileName: ".changelog.txt"
    }
);

dl.on('end', () => console.log('Download Completed'))
dl.start();
Chaphasilor commented 3 years ago

I think this happens since #27

Looking at my code it will probably not only filter out trailing dots, but also leading dots.

Since leading dots are very common, I'll come up with a fix for my fix :P

And we could also consider adding an option to force saving it with the original filename, what do you think @hgouveia?

hgouveia commented 3 years ago

Hey @TAINCER , it seems @Chaphasilor will take care of this, in the meantime i suggest you use the filename callback, so you can control the naming

const dl = new DownloaderHelper(
    'https://files.taincer.com/testdata/.changelog.txt',
    __dirname,
    {
        override: true,
        fileName: (fileName, filePath, contentType) => fileName
    }
);

@Chaphasilor please go ahead

hgouveia commented 2 years ago

fixed on #59