Code Monkey home page Code Monkey logo

multi-threaded-downloader's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.