
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
minipass-sized
Advanced tools
A Minipass stream that raises an error if you get a different number of bytes than expected
The minipass-sized npm package is a stream library that extends Minipass with support for ensuring a specific number of bytes are written to the stream. It is useful for scenarios where you need to validate the size of the stream data, such as when receiving files or data packets that must meet specific size requirements.
Size validation
This feature allows the user to set a specific size for the stream and emits an event or an error if the stream does not match the specified size. It is particularly useful for validating the integrity of data in scenarios where the exact size is critical.
const MinipassSized = require('minipass-sized');
const stream = new MinipassSized({ size: 1024 });
stream.on('size', () => console.log('Size is exactly 1024 bytes'));
stream.on('error', (err) => console.error('Error:', err.message));
Concat-stream is a writable stream that concatenates data and calls a callback with the result. It is similar to minipass-sized in that it processes stream data but does not provide built-in size validation.
Buffer list (bl) is a storage object for collections of Node.js Buffers, similar to minipass-sized in handling stream data. Unlike minipass-sized, bl focuses on buffer management and aggregation rather than enforcing size constraints.
A Minipass stream that raises an error if you get a different number of bytes than expected.
Use just like any old minipass stream, but
provide a size
option to the constructor.
The size
option must be a positive integer, smaller than
Number.MAX_SAFE_INTEGER
.
const MinipassSized = require('minipass-sized')
// figure out how much data you expect to get
const expectedSize = +headers['content-length']
const stream = new MinipassSized({ size: expectedSize })
stream.on('error', er => {
// if it's the wrong size, then this will raise an error with
// { found: <number>, expect: <number>, code: 'EBADSIZE' }
})
response.pipe(stream)
Caveats: this does not work with objectMode
streams, and will throw a
TypeError
from the constructor if the size argument is missing or
invalid.
FAQs
A Minipass stream that raises an error if you get a different number of bytes than expected
We found that minipass-sized 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.