Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
stream-counter
Advanced tools
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.
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}`);
});
The byte-stream package provides similar functionality for counting bytes in a stream. It offers additional features such as limiting the number of bytes read and pausing the stream when the limit is reached. Compared to stream-counter, byte-stream provides more control over the stream processing.
The stream-meter package is another alternative for measuring the size of data in a stream. It provides a simple interface for tracking the number of bytes and can be used in a similar manner to stream-counter. However, stream-meter focuses solely on measuring data size without additional stream control features.
Keep track of how many bytes have been written to a stream.
var StreamCounter = require('stream-counter');
var counter = new StreamCounter();
counter.on('progress', function() {
console.log("progress", counter.bytes);
});
fs.createReadStream('foo.txt').pipe(counter);
FAQs
keeps track of how many bytes have been written to a stream
The npm package stream-counter receives a total of 137,249 weekly downloads. As such, stream-counter popularity was classified as popular.
We found that stream-counter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.