fetchsource

1.0.2 • Public • Published

fetchsource

High performance fetch source, support continue transfering from break point.

NPM version License npm node

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);
    }
} )();

Readme

Keywords

Package Sidebar

Install

npm i fetchsource

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

19.1 kB

Total Files

4

Last publish

Collaborators

  • cxm