Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toyobayashi/downloader
https://github.com/toyobayashi/downloader
Last synced: 2 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/toyobayashi/downloader
- Owner: toyobayashi
- Created: 2021-04-19T10:37:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-31T09:08:25.000Z (over 3 years ago)
- Last Synced: 2024-10-11T20:58:35.221Z (27 days ago)
- Language: TypeScript
- Size: 92.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# downloader
Tiny downloader in Node.js
[API Documentation](https://github.com/toyobayashi/downloader/blob/main/docs/api/index.md)
## Usage
```bash
npm install @tybys/downloader
``````js
const { Downloader, DownloadOverwrite } = require('@tybys/downloader')const downloader = new Downloader()
downloader.settings.maxConcurrentDownloads = 1
downloader.settings.overwrite = DownloadOverwrite.RENAMEconst 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)
```