fetchsource
v1.0.2
Published
High performance fetch source, support continue transfering from break point.
Downloads
1
Readme
fetchsource
High performance fetch source, support continue transfering from break point.
npm install fetchsource
const Fetch = require('fetchsource');
// options: maxRedirects:number timeout:number(ms) headers:object output:string(fetch file path) url:string
const fetchUrl = 'https://github.com/chenxianming/sqapi/archive/master.zip';
let fetchSource = new Fetch({
url:fetchUrl,
timeout: 6000,
output: './temp',
onProgress(len, cur, tol) {
console.log( ~~( cur / tol * 100 ) + '%' );
console.log( len, cur, tol );
}
});
// By chain called
fetchSource.then( ( request ) => {
console.log('The file save as ./temp');
} ).catch( e => console.log(e) );
// By async/await
( async() => {
try{
await fetchSource;
console.log('The file save as ./temp');
}catch(e){
console.log(e);
}
} )();