Socket
Socket
Sign inDemoInstall

minipass-sized

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    minipass-sized

A Minipass stream that raises an error if you get a different number of bytes than expected


Version published
Weekly downloads
8.4M
decreased by-17.78%
Maintainers
1
Install size
175 kB
Created
Weekly downloads
 

Package description

What is minipass-sized?

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.

What are minipass-sized's main functionalities?

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));

Other packages similar to minipass-sized

Readme

Source

minipass-sized

A Minipass stream that raises an error if you get a different number of bytes than expected.

USAGE

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.

Keywords

FAQs

Last updated on 30 Sep 2019

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