2.2.0 • Published 7 months ago

electron-dl-downloader v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

electron-dl-downloader

Electron app simple and easy to use download manager, support for multiple downloads

Why?

  • Simple to use, few call parameters
  • No electron window object is required
  • Support for multiple downloads (Associate by url)
  • Perfect compatibility with electron api

Install

npm i electron-dl-downloader

Usage

const Downloader = require('electron-dl-downloader');
const dl = new Downloader({url:'https://xx.exe', filePath:'D:\\Downloads\\oo.exe'});
//const dl = new Downloader({url:'https://xx.exe', directory:'D:\\Downloads'});
//const dl = new Downloader({url:'https://xx.exe', directory:'D:\\Downloads', fileName:'oo.exe'});
const item = await dl.download()
const state = await dl.whenDone()

if (state === Downloader.STATES.completed) {
    console.log('Download successfully')
} else {
    console.log(`Download failed: ${state}`)
}

Electron DownloadItem events and methods are also supported.\ https://www.electronjs.org/docs/latest/api/download-item

const item = await dl.download()

item.on('updated', (event, state) => {
    if (state === Downloader.STATES.interrupted) {
        console.log('Download is interrupted but can be resumed')
    } else if (state === Downloader.STATES.progressing) {
        if (item.isPaused()) {
            console.log('Download is paused')
        } else {
            console.log(`Received bytes: ${item.getReceivedBytes()}`)
        }
    }
})

item.pause()

API

It can only be used in the main process.

Class: Downloader

constructor()

constructor(params)

params: {
    url: string,
    filePath: string, //such as "D:\\Downloads\\oo.exe"
    directory: string, //such as "D:\\Downloads". default:Directory for a user's downloads.
    fileName: string, //such as "oo.exe". default:Electron downloadItem.getFilename()
    timeout: number,  //second. default 60 (Deprecated since v2.1.0)
    options: object //Electron downloadURL options
}

Instance Methods

download()

Starts a file download. Returns the DownloadItem of the download.

download(): Promise<DownloadItem>

whenDone()

Wait for the "done" event for DownloadItem and returns state string

whenDone(): Promise<string>

Instance Properties

url

Returns arg url

filePath

Returns arg filePath

Static Properties

STATES

Returns downloadItem state object

2.1.2

7 months ago

2.2.0

7 months ago

2.1.1

7 months ago

2.1.0

7 months ago

2.0.5

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.0

1 year ago

1.0.5

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago