WebSocket buffer utils
npm install websocketutilswebsocketutils is what makes ws fast. It provides some utilities to efficiently
npm install websocketutils --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.
$3
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
`js
'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);
`
$3
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
`js
'use strict';
const bufferUtil = require('bufferutil');
const crypto = require('crypto');
const buffer = crypto.randomBytes(10);
const mask = crypto.randomBytes(4);
bufferUtil.unmask(buffer, mask);
``