JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6753742
  • Score
    100M100P100Q206444F
  • License MIT

Tracks the download progress of a request made with mikeal/request

Package Exports

  • request-progress

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (request-progress) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

request-progress Build Status

Tracks the download progress of a request made with request.

Installation

$ npm install request-progress

Usage

var fs = require('fs');
var request = require('request');
var progress = require('request-progress');

// Note that the options argument is optional
progress(request('http://google.com/doodle.png'), {
    throttle: 2000,                    // Throttle the progress event to 2000ms, defaults to 1000ms
    delay: 1000,                       // Only start to emit after 1000ms delay, defaults to 0ms
    lengthHeader: 'x-transfer-length'  // Length header to use, defaults to content-length
})
.on('progress', function (state) {
    console.log('received size in bytes', state.received);
    // The properties bellow can be null if response does not contain
    // the content-length header
    console.log('total size in bytes', state.total);
    console.log('percent', state.percent);
    console.log('eta', state.eta);
})
.on('error', function (err) {
    // Do something with err
})
.pipe(fs.createWriteStream('doodle.png'));

Note that the state object emitted in the progress event is reused to avoid creating a new object for each event.
If you wish to peek the state object at any time, it is available in request.progressState.

License

Released under the MIT License.