
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
byte-counter
Advanced tools
Count bytes passing through a stream
A transform stream that counts bytes passing through without modifying the data. Useful for tracking data transfer size, monitoring progress, or validating content-length headers.
The main export uses Web Streams. For Node.js streams, use the /node subexport.
npm install byte-counter
import ByteCounterStream from 'byte-counter';
const counter = new ByteCounterStream();
const response = await fetch('https://example.com/large-file.zip');
await response.body
.pipeThrough(counter)
.pipeTo(new WritableStream({
write(chunk) {
// Process chunk
},
close() {
console.log(`Downloaded ${counter.count} bytes`);
}
}));
import ByteCounterStream from 'byte-counter';
const counter = new ByteCounterStream();
const encoder = new TextEncoder();
const writer = counter.writable.getWriter();
await writer.write(encoder.encode('Hello '));
await writer.write(encoder.encode('World'));
await writer.close();
console.log(counter.count);
//=> 11
A TransformStream that counts bytes passing through without modifying the data.
Type: number (read-only)
The number of bytes that have passed through the stream.
Calculate the byte length of some data.
Strings are measured as UTF-8 bytes.
import {byteLength} from 'byte-counter';
byteLength('Hello');
//=> 5
byteLength('Hello 👋');
//=> 10
byteLength(new Uint8Array([1, 2, 3]));
//=> 3
Type: string | Uint8Array | ArrayBuffer | SharedArrayBuffer | ArrayBufferView
The data to measure.
Returns: number - The byte length of the data.
byte-counter/node)A Node.js Transform stream that counts bytes passing through without modifying the data.
import fs from 'node:fs';
import ByteCounterStream from 'byte-counter/node';
const counter = new ByteCounterStream();
fs.createReadStream('file.txt')
.pipe(counter)
.pipe(fs.createWriteStream('output.txt'))
.on('finish', () => {
console.log(`Transferred ${counter.count} bytes`);
});
import ByteCounterStream from 'byte-counter/node';
const counter = new ByteCounterStream();
const encoder = new TextEncoder();
counter.write(encoder.encode('Hello '));
counter.write(encoder.encode('World'));
counter.end();
console.log(counter.count);
//=> 11
Type: number (read-only)
The number of bytes that have passed through the stream.
FAQs
Count bytes passing through a stream
The npm package byte-counter receives a total of 1,154,244 weekly downloads. As such, byte-counter popularity was classified as popular.
We found that byte-counter demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.