Socket
Socket
Sign inDemoInstall

progress-stream

Package Overview
Dependencies
8
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    progress-stream

Read the progress of a stream


Version published
Weekly downloads
425K
decreased by-1.74%
Maintainers
1
Install size
174 kB
Created
Weekly downloads
 

Package description

What is progress-stream?

The `progress-stream` npm package is used to monitor the progress of data being streamed. It is particularly useful for tracking the progress of file uploads, downloads, or any other data transfer operations. The package provides a simple interface to get updates on the amount of data transferred, the speed of transfer, and the estimated time remaining.

What are progress-stream's main functionalities?

Basic Progress Tracking

This feature allows you to track the progress of a file being read and written. The `progress` event provides updates on the percentage completed, the speed of transfer, and the estimated time remaining.

const progress = require('progress-stream');
const fs = require('fs');

const stat = fs.statSync('file.txt');
const str = progress({ length: stat.size, time: 100 });

str.on('progress', function(progress) {
  console.log(progress);
});

fs.createReadStream('file.txt').pipe(str).pipe(fs.createWriteStream('copy.txt'));

Custom Progress Handling

This feature allows for custom handling of progress updates. You can log specific details such as the number of bytes transferred, the speed of transfer, and the estimated time remaining.

const progress = require('progress-stream');
const fs = require('fs');

const stat = fs.statSync('file.txt');
const str = progress({ length: stat.size, time: 100 });

str.on('progress', function(progress) {
  console.log(`Transferred: ${progress.transferred} bytes`);
  console.log(`Speed: ${progress.speed} bytes/sec`);
  console.log(`ETA: ${progress.eta} seconds`);
});

fs.createReadStream('file.txt').pipe(str).pipe(fs.createWriteStream('copy.txt'));

Other packages similar to progress-stream

Readme

Source

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 copies a large file, and prints out the percentage every 100ms.

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

var stat = fs.statSync(filename);
var p = progress({
	length: stat.size,
	time: 100
});

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

fs.createReadStream(filename)
	.pipe(p)
	.pipe(fs.createWriteStream(output));

Methods

progress([options], [onprogress])

You can instantiate in two ways:

var p = progress({time:100});
p.on('progress', function(progress) { ... });

or inline the onprogress event

var p = progress({time:100}, function(progress) { ... });

Events

on('progress', onprogress)

var p = progress({time:100});
p.on('progress', function(progress) { ... });

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-stream');
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.

Keywords

FAQs

Last updated on 11 Dec 2013

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