Skip to content

Latest commit

 

History

History
129 lines (97 loc) · 4.07 KB

README.md

File metadata and controls

129 lines (97 loc) · 4.07 KB


filedownloader

github issues travis

npm version npm downloads Standard - JavaScript Style Guide


**filedownloader** is a small module for easy downloading using the power of curl combined with node.js

Note

this module requires curl to be present in your system path. if not please check those links

Linux Windows Mac Os

Quick start

Install

To install filedownloader for use in node require('filedownloader'), run:

	npm install filedownloader

Usage

    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 from
  • saveAs 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

Controlling The Download

you can pause the downloading by :

    Dl.pause();

and you can resume it by:

    Dl.resume();

Setting event handlers

'start': download started

The start event is emitted just after the download starts

    Dl.on("start", () => console.log("Download started"));

'progress': progress information

The progress Event is emitted with an object argument with the following keys:

  • dataWritten: size of downloaded data in bytes
  • filesize: size of the target file in bytes
  • progress: an estimation of the progress between 0 and 1
  • speed: an estimation of the download speed
    Dl.on("progress", progress => console.log(progress.progress));

'error': error occurred

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

'end': Downloading finished

The end event is emitted when Downloading has finished.

    Dl.on("end", () => console.log('Download finished'));

What's new

Tests

npm test

Dependencies

  • 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

Author

Oussama Barkouki

License