@tybys/downloader
v0.2.0
Published
Tiny downloader in Node.js
Downloads
13
Readme
downloader
Tiny downloader in Node.js
Usage
npm install @tybys/downloader
const { Downloader, DownloadOverwrite } = require('@tybys/downloader')
const downloader = new Downloader()
downloader.settings.maxConcurrentDownloads = 1
downloader.settings.overwrite = DownloadOverwrite.RENAME
const electron1204 = downloader.add('https://npm.taobao.org/mirrors/electron/12.0.4/electron-v12.0.4-win32-x64.zip', {
dir: __dirname,
out: 'electron-v12.0.4-win32-x64.zip'
})
const electron1203 = downloader.add('https://npm.taobao.org/mirrors/electron/12.0.3/electron-v12.0.3-win32-x64.zip', {
dir: __dirname,
out: 'electron-v12.0.3-win32-x64.zip'
})
const onProgress = (downloadProgress) => {
if (process.stdout.clearLine) {
process.stdout.clearLine(0)
process.stdout.cursorTo(0)
process.stdout.write(`percent: ${downloadProgress.percent}, speed: ${downloadProgress.downloadSpeed / 1000} KB/s`)
}
}
electron1204.on('progress', onProgress)
electron1203.on('progress', onProgress)
electron1204.on('fail', () => {
console.log(electron1204.error)
})
electron1204.whenStopped().then(() => {
console.log('whenStopped ' + electron1204.gid)
}).catch(err => {
console.log(err.message)
})
electron1203.whenStopped().then(() => {
console.log('whenStopped ' + electron1203.gid)
}).catch(err => {
console.log(err.message)
})
setTimeout(() => {
electron1204.abort()
}, 2000)