Skip to content

Electron app simple and easy to use download manager, support for multiple downloads.Electron应用简单和易用的下载管理,支持多任务下载

License

Notifications You must be signed in to change notification settings

xianyunleo/electron-dl-downloader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
  • Support timeout
  • 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
    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

About

Electron app simple and easy to use download manager, support for multiple downloads.Electron应用简单和易用的下载管理,支持多任务下载

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published