**filedownloader** is a small module for easy downloading using the power of curl combined with node.js
this module requires curl to be present in your system path. if not please check those links
To install filedownloader for use in node require('filedownloader')
, run:
npm install filedownloader
const Downloader = require("filedownloader");
const Dl = new Downloader({
url: "FILEURL"
}).on("progress", progress => console.log(progress));
The Downloader function accepts an object that can take:
url
url to Download fromsaveAs
Filename to be saved as ex( audio.mp3)saveTo
Folder to be saved in (default: current working directory)deleteIfExists
Delete file if it does exist (default: false)resume
Resume file if it's not completed, if false will delete the file and start it again (default: true)
The progress event will return :
{ progress: 0.13, dataWritten: 376072, filesize: '29828970', speed: 'byte/s'} //just an example of the ouput
you can pause the downloading by :
Dl.pause();
and you can resume it by:
Dl.resume();
The start
event is emitted just after the download starts
Dl.on("start", () => console.log("Download started"));
The progress
Event is emitted with an object argument with the following keys:
dataWritten
: size of downloaded data in bytesfilesize
: size of the target file in bytesprogress
: an estimation of the progress between 0 and 1speed
: an estimation of the download speed
Dl.on("progress", progress => console.log(progress.progress));
The error
event is emitted when an error occurs
Dl.on("error", err => console.log('Some error occurred:' + err));
Note: err is always an instance of Error
The end
event is emitted when Downloading has finished.
Dl.on("end", () => console.log('Download finished'));
-
getCurl function that returns the curl process instance
for more details: https://nodejs.org/api/child_process.html
-
following standard js
npm test
- bluebird: full featured promise library with unmatched performance.
- content-disposition: Create and parse Content-Disposition header
- del: Delete files and folders
- mkdirp: Recursively mkdir, like
mkdir -p
- request: Simplified HTTP request client.
- valid-url: URI validation functions
Oussama Barkouki
- GPL-3.0 : http://opensource.org/licenses/GPL-3.0