JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 394742
  • Score
    100M100P100Q181871F
  • License BSD-2-Clause

Read the progress of a stream

Package Exports

  • progress-stream

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 (progress-stream) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

progress-stream

Read the progress of a stream. You can either instantiate it with a specific length, or it will read the length automatically if you're using the request module or http module.

npm install progress-stream

Usage

This example reads 100 MB from stdin, and writes out the percentage every 100ms.

var progress = require('progress-stream');

p = progress({
    time: 100,
    length: 100000000
});
p.on('progress', function(progress) {
    console.log(progress.percentage);
});

process.stdin.pipe();

Options

time(integer)

Sets how often progress events is emitted. If omitted then defaults to emit every time a chunk is received.

length(integer)

If you already know the length of the stream, then you can set it. Defaults to 0.

drain(boolean)

In case you don't want to include a readstream after progress-stream, set to true to drain automatically. Defaults to false.

Examples

Using the request module

This example uses request to download a 100 MB file, and writes out the percentage every second.

You can also find an example in test/request.js.

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

var p = progress({
    time: 1000
});

p.on('progress', function(progress) {
    console.log(Math.round(progress.percentage)+'%');
});

req('http://cachefly.cachefly.net/100mb.test', { headers: { 'user-agent': 'test' }})
    .pipe(p)
    .pipe(fs.createWriteStream('test.data'));

Using the http module

In test/http.js it's shown how to do it with the http module.