Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
bufferutil
Advanced tools
WebSocket buffer utils
Weekly downloads
Package description
The bufferutil package is a Node.js utility module that provides efficient buffer operations. It is primarily used to enhance the performance of binary data manipulation by providing a native addon for buffer operations which are faster than pure JavaScript implementations.
Masking and unmasking WebSocket frames
This feature allows you to mask and unmask data according to the WebSocket protocol, which is useful for WebSocket frame manipulation.
const bufferUtil = require('bufferutil');
const buffer = Buffer.from('Hello World');
const masked = bufferUtil.mask(buffer, Buffer.from([0x12, 0x34, 0x56, 0x78]));
const unmasked = bufferUtil.unmask(masked, Buffer.from([0x12, 0x34, 0x56, 0x78]));
Buffer concatenation
This feature provides a method to concatenate multiple buffers into a single buffer efficiently.
const bufferUtil = require('bufferutil');
const buffers = [Buffer.from('Hello'), Buffer.from(' '), Buffer.from('World')];
const concatenated = bufferUtil.concat(buffers);
Buffer comparison
This feature allows you to compare two buffers for equality, which is faster than comparing them byte-by-byte in JavaScript.
const bufferUtil = require('bufferutil');
const buffer1 = Buffer.from('Hello');
const buffer2 = Buffer.from('Hello');
const isEqual = bufferUtil.equals(buffer1, buffer2);
The 'ws' package is a WebSocket client and server implementation for Node.js. It includes a built-in buffer utility for masking and unmasking WebSocket frames, similar to bufferutil, but it is a more comprehensive solution for working with WebSockets.
The 'buffer' package is a Node.js core module that provides a way to handle binary data. It includes methods for manipulating buffers but does not have the native performance optimizations that bufferutil offers.
The 'buffers' package provides a way to work with collections of Node.js Buffer objects. It offers buffer manipulation capabilities like concatenation and slicing, but it does not focus on WebSocket frame manipulation or the native performance enhancements found in bufferutil.
Readme
Buffer utils is one of the modules that makes ws
fast. It's optimized for
certain buffer based operations such as merging buffers, generating WebSocket
masks and unmasking.
As the module consists of binary components, it should be used an
optionalDependency
so when installation fails, it doesn't halt the
installation of your module. There are fallback files available in this
repository. See fallback.js
for the suggest fallback implementation if
installation fails.
npm install bufferutil
In all examples we assume that you've already required the BufferUtil as followed:
'use strict';
var bu = require('bufferutil').BufferUtil;
The module exposes 3 different functions:
Merge multiple buffers in the first supplied buffer argument:
bu.merge(buffer, [buffer1, buffer2]);
This merges buffer1 and buffer2 which are in an array into buffer.
Apply a WebSocket mask on the given data.
bu.mask(buffer, mask);
Remove a WebSocket mask on the given data.;w
bu.unmask(buffer, mask);
MIT
FAQs
WebSocket buffer utils
The npm package bufferutil receives a total of 1,219,515 weekly downloads. As such, bufferutil popularity was classified as popular.
We found that bufferutil demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.