Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

bufferutil

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bufferutil - npm Package Compare versions

Comparing version
1.1.0
to
1.2.0
+5
.travis.yml
language: node_js
node_js:
- "0.12"
- "0.10"
- "iojs"
# bufferutil
Buffer utils is one of the modules that makes `ws` fast. It's optimized for
certain buffer based operations such as merging buffers, generating WebSocket
masks and unmasking.
As the module consists of binary components, it should be used an
`optionalDependency` so when installation fails, it doesn't halt the
installation of your module. There are fallback files available in this
repository. See `fallback.js` for the suggest fallback implementation if
installation fails.
## Installation
```
npm install bufferutil
```
## API
In all examples we assume that you've already required the BufferUtil as
followed:
```js
'use strict';
var bu = require('bufferutil').BufferUtil;
```
The module exposes 3 different functions:
#### merge
Merge multiple buffers in the first supplied buffer argument:
```js
bu.merge(buffer, [buffer1, buffer2]);
```
This merges buffer1 and buffer2 which are in an array into buffer.
#### mask
Apply a WebSocket mask on the given data.
```js
bu.mask(buffer, mask);
```
#### unmask
Remove a WebSocket mask on the given data.;w
```js
bu.unmask(buffer, mask);
```
## License
MIT
+15
-10

@@ -11,6 +11,5 @@ 'use strict';

merge: function(mergedBuffer, buffers) {
var offset = 0;
for (var i = 0, offset = 0, l = buffers.length; i < l; ++i) {
var buf = buffers[i];
for (var i = 0, l = buffers.length; i < l; ++i) {
var buf = buffers[i];
buf.copy(mergedBuffer, offset);

@@ -20,8 +19,11 @@ offset += buf.length;

},
mask: function(source, mask, output, offset, length) {
var maskNum = mask.readUInt32LE(0, true);
var i = 0;
var maskNum = mask.readUInt32LE(0, true)
, i = 0
, num;
for (; i < length - 3; i += 4) {
var num = maskNum ^ source.readUInt32LE(i, true);
num = maskNum ^ source.readUInt32LE(i, true);
if (num < 0) num = 4294967296 + num;

@@ -37,9 +39,12 @@ output.writeUInt32LE(num, offset + i, true);

},
unmask: function(data, mask) {
var maskNum = mask.readUInt32LE(0, true);
var length = data.length;
var i = 0;
var maskNum = mask.readUInt32LE(0, true)
, length = data.length
, i = 0
, num;
for (; i < length - 3; i += 4) {
var num = maskNum ^ data.readUInt32LE(i, true);
num = maskNum ^ data.readUInt32LE(i, true);
if (num < 0) num = 4294967296 + num;

@@ -46,0 +51,0 @@ data.writeUInt32LE(num, i, true);

+3
-3
{
"name": "bufferutil",
"version": "1.1.0",
"version": "1.2.0",
"description": "WebSocket buffer utils",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Only testing builds, test have to be extraced from `ws`\" && exit 0"
},

@@ -24,4 +24,4 @@ "repository": {

"bindings": "1.2.x",
"nan": "1.8.x"
"nan": "^2.0.5"
}
}

@@ -27,9 +27,9 @@ /*!

{
NanScope();
Local<FunctionTemplate> t = NanNew<FunctionTemplate>(New);
Nan::HandleScope scope;
Local<FunctionTemplate> t = Nan::New<FunctionTemplate>(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_METHOD(t, "unmask", BufferUtil::Unmask);
NODE_SET_METHOD(t, "mask", BufferUtil::Mask);
NODE_SET_METHOD(t, "merge", BufferUtil::Merge);
target->Set(NanNew<String>("BufferUtil"), t->GetFunction());
Nan::SetMethod(t, "unmask", BufferUtil::Unmask);
Nan::SetMethod(t, "mask", BufferUtil::Mask);
Nan::SetMethod(t, "merge", BufferUtil::Merge);
Nan::Set(target, Nan::New<String>("BufferUtil").ToLocalChecked(), t->GetFunction());
}

@@ -41,6 +41,6 @@

{
NanScope();
Nan::HandleScope scope;
BufferUtil* bufferUtil = new BufferUtil();
bufferUtil->Wrap(args.This());
NanReturnValue(args.This());
bufferUtil->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}

@@ -50,6 +50,6 @@

{
NanScope();
Local<Object> bufferObj = args[0]->ToObject();
Nan::HandleScope scope;
Local<Object> bufferObj = info[0]->ToObject();
char* buffer = Buffer::Data(bufferObj);
Local<Array> array = Local<Array>::Cast(args[1]);
Local<Array> array = Local<Array>::Cast(info[1]);
unsigned int arrayLength = array->Length();

@@ -64,3 +64,3 @@ size_t offset = 0;

}
NanReturnValue(NanTrue());
info.GetReturnValue().Set(Nan::True());
}

@@ -70,6 +70,6 @@

{
NanScope();
Local<Object> buffer_obj = args[0]->ToObject();
Nan::HandleScope scope;
Local<Object> buffer_obj = info[0]->ToObject();
size_t length = Buffer::Length(buffer_obj);
Local<Object> mask_obj = args[1]->ToObject();
Local<Object> mask_obj = info[1]->ToObject();
unsigned int *mask = (unsigned int*)Buffer::Data(mask_obj);

@@ -87,3 +87,3 @@ unsigned int* from = (unsigned int*)Buffer::Data(buffer_obj);

}
NanReturnValue(NanTrue());
info.GetReturnValue().Set(Nan::True());
}

@@ -93,9 +93,9 @@

{
NanScope();
Local<Object> buffer_obj = args[0]->ToObject();
Local<Object> mask_obj = args[1]->ToObject();
Nan::HandleScope scope;
Local<Object> buffer_obj = info[0]->ToObject();
Local<Object> mask_obj = info[1]->ToObject();
unsigned int *mask = (unsigned int*)Buffer::Data(mask_obj);
Local<Object> output_obj = args[2]->ToObject();
unsigned int dataOffset = args[3]->Int32Value();
unsigned int length = args[4]->Int32Value();
Local<Object> output_obj = info[2]->ToObject();
unsigned int dataOffset = info[3]->Int32Value();
unsigned int length = info[4]->Int32Value();
unsigned int* to = (unsigned int*)(Buffer::Data(output_obj) + dataOffset);

@@ -114,3 +114,3 @@ unsigned int* from = (unsigned int*)Buffer::Data(buffer_obj);

}
NanReturnValue(NanTrue());
info.GetReturnValue().Set(Nan::True());
}

@@ -124,3 +124,3 @@ };

{
NanScope();
Nan::HandleScope scope;
BufferUtil::Initialize(target);

@@ -130,2 +130,1 @@ }

NODE_MODULE(bufferutil, init)