Socket
Socket
Sign inDemoInstall

bufferutil

Package Overview
Dependencies
14
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

bufferutil

WebSocket buffer utils


Version published
Maintainers
2
Weekly downloads
1,486,949
decreased by-9.18%

Weekly downloads

Package description

What is bufferutil?

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.

What are bufferutil's main functionalities?

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

Other packages similar to bufferutil

Readme

Source

bufferutil

Build Status

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.

Installation

npm install bufferutil

API

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

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.

mask

Apply a WebSocket mask on the given data.

bu.mask(buffer, mask);
unmask

Remove a WebSocket mask on the given data.;w

bu.unmask(buffer, mask);

License

MIT

Keywords

FAQs

Last updated on 21 Aug 2015

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