Skip to content

pavanbuzz/Multi-threaded-downloader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mt-downloader

Build Status npm Commitizen friendly semantic-release js-standard-style

This is a nodejs based module that helps you in performing resumable, multi-threaded downloads via Http. The module is highly inspired by Speedbit's — Download Accelerator Plus.

Features

  1. Multi threaded downloads: In a conventional single threaded download you might experience poor performance due to network lags. So you don't completely utilize your bandwidth. With multiple threads there is always one thread which is getting data thus minimizing the wait period between data packets. This doesn't mean that you will be able to download faster than what your data plan. You will only be able to use the bandwidth in a more optimized fashion.

  2. Stop and start from the last downloaded byte:. You don't have to worry about internet getting disconnected or your computer shutting down while downloading. You can quite easily start from the last byte that was downloaded.

  3. Console application: If installed globally, mtd command would be available.

Installation

The conventional npm installation process needs to be followed.

npm install mt-downloader --save-dev

.mtd file

Once the download starts the library will create a file with a .mtd extension. This file contains some meta information related to the download and is a little bigger (around 512 bytes) than the original download size. The .mtd file can be used later to restart downloads from where the last byte that was downloaded. After the download is completed the downloader will truncate the file to remove that meta data.

New-Downloads

var createDownload = require('mt-downloader').createDownload
var url = 'https://upload.wikimedia.org/wikipedia/commons/4/47/Gadget_the_pug_expressive_eyes.jpg';
var path = '/Users/tusharmathur/Desktop/temp/Gadget_the_pug_expressive_eyes.jpg';
var downloader = createDownload({path, url});
downloader.start() // returns an observable

The start() method returns an observable. It can easily be converted into a promise by calling toPromise() method on it.

downloader.start().toPromise()

Re-Downloads

If you want to restart a download from where it left off. You just need to provide the path of the original file.

//File should have NOT have .mtd extension
var path = '/Users/tusharmathur/Desktop/temp/Gadget_the_pug_expressive_eyes.jpg'
var downloader = createDownload({path})
downloader.download().toPromise()

Event Stream

All the internal events are exposed as an observable via the stats property.

const downloader = createDownload({path, url})
downloader.stats.subscribe((x) => console.log(x))
downloader.start()

/*
OUTPUT {event: <event>, message: <message>}
...
...
...
*/

Events include —

  • INIT: Fired as soon as the download is created.
  • CREATE: Fired when a .mtd file is created.
  • DATA: Fired every time some packet of data is SAVED.
  • TRUNCATE: Fired once the meta info is removed from the .mtd file.
  • RENAME:Fired once the file is renamed from .mtd to the original name.

About

A http file downloader made in nodejs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%