Sha256: 9d38b41cfe97821348e02e219b6485f2d24c281cb18aa2af5530752f46caba38
Contents?: true
Size: 1.36 KB
Versions: 35
Compression:
Stored size: 1.36 KB
Contents
/*! * ws: a node.js websocket client * Copyright(c) 2011 Einar Otto Stangvik <einaros@gmail.com> * MIT Licensed */ 'use strict'; /** * Merges an array of buffers into a target buffer. * * @param {Buffer} target The target buffer * @param {Buffer[]} buffers The array of buffers to merge * @public */ const merge = (target, buffers) => { var offset = 0; for (var i = 0; i < buffers.length; i++) { const buf = buffers[i]; buf.copy(target, offset); offset += buf.length; } }; /** * Masks a buffer using the given mask. * * @param {Buffer} source The buffer to mask * @param {Buffer} mask The mask to use * @param {Buffer} output The buffer where to store the result * @param {Number} offset The offset at which to start writing * @param {Number} length The number of bytes to mask. * @public */ const mask = (source, mask, output, offset, length) => { for (var i = 0; i < length; i++) { output[offset + i] = source[i] ^ mask[i & 3]; } }; /** * Unmasks a buffer using the given mask. * * @param {Buffer} buffer The buffer to unmask * @param {Buffer} mask The mask to use * @public */ const unmask = (buffer, mask) => { // Required until https://github.com/nodejs/node/issues/9006 is resolved. const length = buffer.length; for (var i = 0; i < length; i++) { buffer[i] ^= mask[i & 3]; } }; module.exports = { merge, mask, unmask };
Version data entries
35 entries across 35 versions & 2 rubygems