Luigi Pinca 9eec89acc3 [ci] Use Ubuntu 20.04 to build the prebuilt binary for Linux
The Ubuntu 18.04 Actions runner image is no longer supported.
2023-10-15 17:37:26 +02:00
2018-12-23 08:46:10 +01:00
2017-02-07 16:05:26 +01:00
2022-01-02 09:27:44 +01:00
2020-04-25 15:59:30 +02:00
2018-07-03 08:12:43 +02:00
2018-07-03 08:12:30 +02:00
2022-12-09 16:03:36 +01:00
2022-10-18 15:27:14 +02:00
2022-12-16 10:48:21 +01:00

bufferutil

Version npm Linux/macOS/Windows Build

bufferutil is what makes ws fast. It provides some utilities to efficiently perform some operations such as masking and unmasking the data payload of WebSocket frames.

Installation

npm install bufferutil --save-optional

The --save-optional flag tells npm to save the package in your package.json under the optionalDependencies key.

API

The module exports two functions.

bufferUtil.mask(source, mask, output, offset, length)

Masks a buffer using the given masking-key as specified by the WebSocket protocol.

Arguments

  • source - The buffer to mask.
  • mask - A buffer representing the masking-key.
  • output - The buffer where to store the result.
  • offset - The offset at which to start writing.
  • length - The number of bytes to mask.

Example

'use strict';

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

bufferUtil.unmask(buffer, mask)

Unmasks a buffer using the given masking-key as specified by the WebSocket protocol.

Arguments

  • buffer - The buffer to unmask.
  • mask - A buffer representing the masking-key.

Example

'use strict';

const bufferUtil = require('bufferutil');
const crypto = require('crypto');

const buffer = crypto.randomBytes(10);
const mask = crypto.randomBytes(4);

bufferUtil.unmask(buffer, mask);

License

MIT

S
Description
WebSocket buffer utils
Readme MIT
185 KiB
Languages
C 49.2%
JavaScript 46.2%
Python 4.6%