{"id":47195,"library":"bufferutil","title":"bufferutil","description":"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().","status":"active","version":"4.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/websockets/bufferutil","tags":["javascript","bufferutil"],"install":[{"cmd":"npm install bufferutil","lang":"bash","label":"npm"},{"cmd":"yarn add bufferutil","lang":"bash","label":"yarn"},{"cmd":"pnpm add bufferutil","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only; ESM import will fail.","wrong":"import bufferUtil from 'bufferutil';","symbol":"bufferUtil","correct":"const bufferUtil = require('bufferutil');"},{"note":"The function requires exactly 5 arguments; omitting offset or length will cause a runtime error.","wrong":"bufferUtil.mask(source, mask, output);","symbol":"bufferUtil.mask","correct":"bufferUtil.mask(source, mask, output, offset, length);"},{"note":"Missing mask argument leads to incorrect unmasking or crash.","wrong":"bufferUtil.unmask(buffer);","symbol":"bufferUtil.unmask","correct":"bufferUtil.unmask(buffer, mask);"}],"quickstart":{"code":"const bufferUtil = require('bufferutil');\nconst crypto = require('crypto');\n\nconst source = crypto.randomBytes(10);\nconst mask = crypto.randomBytes(4);\n\nbufferUtil.mask(source, mask, source, 0, source.length);\nconsole.log('Masked buffer:', source);\n\nbufferUtil.unmask(source, mask);\nconsole.log('Unmasked buffer:', source);","lang":"javascript","description":"Demonstrates masking and unmasking a buffer using bufferutil."},"warnings":[{"fix":"Install build tools: `npm install -g node-gyp` or platform-specific prerequisites.","message":"bufferUtil 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.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure source, mask, output are Buffer instances, offset and length are within bounds.","message":"Parameters are not validated for performance; passing incorrect arguments (e.g., wrong length) can cause crashes or undefined behavior.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade Node.js to >=6 or pin bufferutil@2.","message":"Version 3.x dropped Node.js <6 support. Users on older Node versions must stay on bufferutil@2.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Prefer using ws which abstracts bufferutil; avoid direct dependency unless needed.","message":"The library does not have a specific deprecation but is considered low-level; direct API may change in future releases without notice.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Use `--save-optional` as recommended; do not use `--save` or `--save-dev`.","message":"When installing with --save-optional, npm will not fail if compilation fails. Some users think it's required but it's optional.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'4.1.0':14 '6.14.2':17 'acceler':29 'addon':4 'altern':52 'api':62 'bind':35 'buffer':8 'bufferutil':1,70 'c':34 'depend':22,45 'design':27 'direct':39 'frame':31 'function':65 'implement':57 'improv':47 'instal':42 'instead':41 'javascript':55,69 'librari':26 'low':59 'low-mainten':58 'mainten':60 'mask':9,56,66 'meant':37 'nativ':3 'node.js':16 'optim':6 'option':21,44 'perform':48 'process':32 'provid':5 'pure':54 'requir':15 'stabl':61 'two':64 'unmask':11,68 'use':40,50 'util':12 'version':13 'via':33 'websocket':7,30 'ws':25,51","created_at":"2026-06-07T16:50:17.209251+00:00","updated_at":"2026-06-07T16:50:17.209251+00:00","problems":[{"fix":"Recompile: `npm rebuild bufferutil`","cause":"Native addon binary is incompatible with the current Node.js version (ABI mismatch).","error":"Error: Module did not self-register"},{"fix":"Install: `npm install bufferutil --save-optional`","cause":"bufferutil is not installed or is not in node_modules.","error":"Cannot find module 'bufferutil'"},{"fix":"Install build tools: on Windows: `npm install --global windows-build-tools`; on Unix: ensure gcc and python installed.","cause":"Missing build tools (Python, C++ compiler) during npm install.","error":"gyp ERR! build error"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/websockets/bufferutil","github":"https://github.com/websockets/bufferutil","docs":null,"changelog":null,"pypi":null,"npm":"bufferutil","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","performance"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}