1.0.0 • Published 2 years ago

@maksrus/downloader v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Node Downloader

A light-weight Nodejs utility to download files asynchronously. This project was heavily inspired by nodejs-file-downloader.

Comes with ES6 and CommonJs support.

Usage

Each download requires a new Downloader instance to which you can pass a configuration object. The download process is initiated by the Downloader.download() async method.

try {
    const dl = new Downloader({
        url: "https://fancyrandomsite.com/images/coolpicture.jpg",
        directory: "./images",
    });

    await dl.download();

} catch (err) {
    console.error(err);
}

Options

interface DownloaderConfig {
    //Mandatory params
    url: string, // the file source. Both Http and Https are accepted

    //Optionnal params
    directory: string, //the destination directory. New directories will be created automatically. Default : "./"
    fileName: string, //You can rename the file if you wish
    headers: object, //Headers can be added if needed

    //You can pass custom onProgress/onFinish/OnError callback functions to the Downloader in order 
    //to override the default behaviour.
    onProgress: (percent: number, chunk: Buffer, total: number) => void, 
    onFinish: () => void, 
    onError: () => void
}