Nova-Client/Solar/Launcher/node_modules/bufferutil
2023-03-19 19:32:58 +00:00
..
prebuilds !! 2023-03-19 19:32:58 +00:00
src !! 2023-03-19 19:32:58 +00:00
binding.gyp !! 2023-03-19 19:32:58 +00:00
fallback.js !! 2023-03-19 19:32:58 +00:00
index.js !! 2023-03-19 19:32:58 +00:00
LICENSE !! 2023-03-19 19:32:58 +00:00
package.json !! 2023-03-19 19:32:58 +00:00
README.md !! 2023-03-19 19:32:58 +00:00

bufferutil

Version npm Linux/macOS Build 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