Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-counter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-counter

keeps track of how many bytes have been written to a stream

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is stream-counter?

The stream-counter npm package is a utility for counting the number of bytes in a stream. It is particularly useful for tracking the size of data being processed in streaming applications.

What are stream-counter's main functionalities?

Counting Bytes in a Stream

This feature allows you to count the number of bytes in a stream. In this example, a file stream is piped through the StreamCounter, and the total number of bytes is logged once the stream finishes.

const StreamCounter = require('stream-counter');
const fs = require('fs');

const counter = new StreamCounter();
const readStream = fs.createReadStream('example.txt');

readStream.pipe(counter).on('finish', () => {
  console.log(`Total bytes: ${counter.bytes}`);
});

Handling Stream Errors

This feature demonstrates how to handle errors in the stream. If the stream encounters an error, such as a nonexistent file, the error is caught and logged.

const StreamCounter = require('stream-counter');
const fs = require('fs');

const counter = new StreamCounter();
const readStream = fs.createReadStream('nonexistent.txt');

readStream.pipe(counter).on('error', (err) => {
  console.error('Stream error:', err);
}).on('finish', () => {
  console.log(`Total bytes: ${counter.bytes}`);
});

Other packages similar to stream-counter

FAQs

Package last updated on 05 Apr 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc