1.0.4 • Published 3 years ago

@taraus-he/tdunzip v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

download-unzip-node

A simple http file downloader and unzipper for node.js

Install

$ npm install --save @taraus-he/tdunzip
$ yarn add @taraus-he/tdunzip

download

Features:

  • Pause/Resume
  • Progress stats
  • Supports http/https
  • Custom native http request options
  • Support nodejs, electron, nwjs
  • Support tree shaking
  • Typescript

Usage

For a more complete example check example folder

const { DownLoader } = require('download-unzip-node');
or
import { DownLoader } from "download-unzip-node";

const dl = new DownLoader({
  url: 'http://www.ovh.net/files/1Gio.dat',
  destFolder: __dirname,
  fileName: "xxxx.dat",
  config: {
    header: {

    },
  }
});
dl.start();
dl
  .on("start")
  .on("progress", (result) => {
    console.log(result)
  })
  .on("error", (error) => {
    console.log(error)
  })

Options

constructor({ url, destFolder, fileName, config = {}}),

for config
{
  method: 'GET', // Request Method Verb defaul 
  headers: {},  // Custom HTTP Header ex: Authorization, User-Agent
}

Methods

NameDescription
startstarts the downloading
pausepause the downloading
resumeresume the downloading if supported, if not it will start from the beginning
stopstop the downloading and remove the file
getFileTotaltotal file size got from the servere

Events

NameDescription
startEmitted when the .start method is called
progressEmitted every time gets data from the server callback(progress)
progress.speedThe same as progress but emits every 1 second while is downloading callback(progress)
redirectEmitted when the url is redirect
completeEmitted when the downloading has finished callback(downloadInfo)
errorEmitted when there is any error callback(error)

event progress progress object

{
  progress, // the download progress in percentage
  total,    // total file size got from the server
  transfer, // the downloaded amount,
  rest,     // the rest file size,
}

event progress.speed progress object

{
  progress, // the download progress in percentage
  total,    // total file size got from the server
  transfer, // the downloaded amount,
  rest,     // the rest file size,
  speed,    // every 1 second
}

event redirect url string

url  // redirect url

event complete result object

{
  path,     // the file saved path
  fileName  // file name
}  

event error error object

error