Registry / devops / bufferutil

bufferutil

JSON →
library4.1.0jsnpmunverified

A native addon providing optimized WebSocket buffer masking and unmasking utilities. Version 4.1.0 requires Node.js >=6.14.2. It is an optional dependency of the ws library, designed to accelerate WebSocket frame processing via C++ bindings. Not meant for direct use; instead, install as optional dependency to improve performance when using ws. Alternative to pure JavaScript masking implementations. Low-maintenance, stable API with two functions: mask() and unmask().

npm install bufferutil
INSTALL
IMPORT
SIG · BUFFERUTIL
B
bufferutil
devopsjavascriptv4.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

bufferUtil
const bufferUtil = require('bufferutil');
import bufferUtil from 'bufferutil';
This package is CommonJS-only; ESM import will fail.
bufferUtil.mask
bufferUtil.mask(source, mask, output, offset, length);
bufferUtil.mask(source, mask, output);
The function requires exactly 5 arguments; omitting offset or length will cause a runtime error.
bufferUtil.unmask
bufferUtil.unmask(buffer, mask);
bufferUtil.unmask(buffer);
Missing mask argument leads to incorrect unmasking or crash.

Demonstrates masking and unmasking a buffer using bufferutil.

const bufferUtil = require('bufferutil'); const crypto = require('crypto'); const source = crypto.randomBytes(10); const mask = crypto.randomBytes(4); bufferUtil.mask(source, mask, source, 0, source.length); console.log('Masked buffer:', source); bufferUtil.unmask(source, mask); console.log('Unmasked buffer:', source);
Debug
Known issues
gotchabufferUtil is a native addon; if it fails to compile, Node.js will fall back to JavaScript fallback (e.g., in ws). Ensure build tools are installed.
fix
Install build tools: `npm install -g node-gyp` or platform-specific prerequisites.
affects: *
gotchaParameters are not validated for performance; passing incorrect arguments (e.g., wrong length) can cause crashes or undefined behavior.
fix
Ensure source, mask, output are Buffer instances, offset and length are within bounds.
affects: *
breakingVersion 3.x dropped Node.js <6 support. Users on older Node versions must stay on bufferutil@2.
fix
Upgrade Node.js to >=6 or pin bufferutil@2.
affects: >=3.0.0
deprecatedThe library does not have a specific deprecation but is considered low-level; direct API may change in future releases without notice.
fix
Prefer using ws which abstracts bufferutil; avoid direct dependency unless needed.
affects: >=4.0.0
gotchaWhen installing with --save-optional, npm will not fail if compilation fails. Some users think it's required but it's optional.
fix
Use `--save-optional` as recommended; do not use `--save` or `--save-dev`.
affects: *
Errors
Common errors & fixes
Error: Module did not self-register
Native addon binary is incompatible with the current Node.js version (ABI mismatch).
fix
Recompile: `npm rebuild bufferutil`
Cannot find module 'bufferutil'
bufferutil is not installed or is not in node_modules.
fix
Install: `npm install bufferutil --save-optional`
gyp ERR! build error
Missing build tools (Python, C++ compiler) during npm install.
fix
Install build tools: on Windows: `npm install --global windows-build-tools`; on Unix: ensure gcc and python installed.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
66 hits · last 30 days
node
58
OpenAI (training)
1
Resources
bufferutil — npm install bufferutil · libregistry