Socket
Socket
Sign inDemoInstall

request-progress

Package Overview
Dependencies
2
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    request-progress

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


Version published
Maintainers
1
Install size
14.8 kB
Created

Readme

Source

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.

Keywords

FAQs

Last updated on 29 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc