https://github.com/qquanwei/js-downloader
Javascript downloader
https://github.com/qquanwei/js-downloader
Last synced: 2 months ago
JSON representation
Javascript downloader
- Host: GitHub
- URL: https://github.com/qquanwei/js-downloader
- Owner: Qquanwei
- Created: 2016-08-26T08:30:49.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-09T02:35:54.000Z (over 8 years ago)
- Last Synced: 2025-04-27T15:24:07.142Z (2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#JS-DOWNLOADER
Features:
* download
* pause
* resume
* progress## Install
* npm install js-downloader --save
## Usage
```
"use strict"
let fs = require('fs');
let download = require('js-downloader');/*
* defaultoption ={
* resume: true, // resume switch
* output:{
* path: '/tmp',
* filename: $urlfilename,
* },
* headers:{}
* }
* */download('http://localhost:8000/setup.exe',{}).then(function(req){
/*
* req = {
* request,
* stream, //download fullpath,will be write'
* }
* */let stream = req.stream;
req.request
.on('end',()=>console.log('done'))
.on('error',console.log)
.on('progress',console.log)
.on('abort',()=>console.log('abort'))
.pipe(stream);setTimeout(function(){
req.request.abort(); // will be abort
},10000);}).catch(function(e){
if(e.message === 'file is done'){
//ignore , local file is already download
}else
console.log(e);
});
```