Comparing version 2.0.1 to 2.0.2
@@ -9,23 +9,49 @@ /*! | ||
exports.BufferUtil = { | ||
merge: function (mergedBuffer, buffers) { | ||
var offset = 0; | ||
for (var i = 0, l = buffers.length; i < l; ++i) { | ||
var buf = buffers[i]; | ||
buf.copy(mergedBuffer, offset); | ||
offset += buf.length; | ||
} | ||
}, | ||
mask: function (source, mask, output, offset, length) { | ||
for (var i = 0; i < length; i++) { | ||
output[offset + i] = source[i] ^ mask[i & 3]; | ||
} | ||
}, | ||
unmask: function (data, mask) { | ||
// required until https://github.com/nodejs/node/issues/9006 is resolved | ||
var length = data.length; | ||
for (var i = 0; i < length; i++) { | ||
data[i] ^= mask[i & 3]; | ||
} | ||
/** | ||
* 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 }; |
@@ -10,5 +10,7 @@ 'use strict'; | ||
try { | ||
module.exports = require('bufferutil'); | ||
const bufferUtil = require('bufferutil'); | ||
module.exports = bufferUtil.BufferUtil || bufferUtil; | ||
} catch (e) { | ||
module.exports = require('./BufferUtil.fallback'); | ||
} |
@@ -10,4 +10,4 @@ /*! | ||
const PerMessageDeflate = require('./PerMessageDeflate'); | ||
const bufferUtil = require('./BufferUtil').BufferUtil; | ||
const Validation = require('./Validation').Validation; | ||
const isValidUTF8 = require('./Validation'); | ||
const bufferUtil = require('./BufferUtil'); | ||
const ErrorCodes = require('./ErrorCodes'); | ||
@@ -364,3 +364,3 @@ | ||
} else { | ||
if (!Validation.isValidUTF8(buf)) { | ||
if (!isValidUTF8(buf)) { | ||
this.error(new Error('invalid utf8 sequence'), 1007); | ||
@@ -401,3 +401,3 @@ return; | ||
if (!Validation.isValidUTF8(buf)) { | ||
if (!isValidUTF8(buf)) { | ||
this.error(new Error('invalid utf8 sequence'), 1007); | ||
@@ -404,0 +404,0 @@ return; |
@@ -12,3 +12,3 @@ /*! | ||
const PerMessageDeflate = require('./PerMessageDeflate'); | ||
const bufferUtil = require('./BufferUtil').BufferUtil; | ||
const bufferUtil = require('./BufferUtil'); | ||
const ErrorCodes = require('./ErrorCodes'); | ||
@@ -15,0 +15,0 @@ |
@@ -9,6 +9,2 @@ /*! | ||
exports.Validation = { | ||
isValidUTF8: function (buffer) { | ||
return true; | ||
} | ||
}; | ||
module.exports = () => true; |
@@ -10,5 +10,9 @@ /*! | ||
try { | ||
module.exports = require('utf-8-validate'); | ||
const isValidUTF8 = require('utf-8-validate'); | ||
module.exports = typeof isValidUTF8 === 'object' | ||
? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0 | ||
: isValidUTF8; | ||
} catch (e) { | ||
module.exports = require('./Validation.fallback'); | ||
} |
@@ -5,3 +5,3 @@ { | ||
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82446
2320