Socket
Socket
Sign inDemoInstall

socket.io-parser

Package Overview
Dependencies
5
Maintainers
2
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.1 to 2.3.2

91

binary.js

@@ -20,35 +20,34 @@ /*global Blob,File*/

exports.deconstructPacket = function(packet){
exports.deconstructPacket = function(packet) {
var buffers = [];
var packetData = packet.data;
var pack = packet;
pack.data = _deconstructPacket(packetData, buffers);
pack.attachments = buffers.length; // number of binary 'attachments'
return {packet: pack, buffers: buffers};
};
function _deconstructPacket(data) {
if (!data) return data;
function _deconstructPacket(data, buffers) {
if (!data) return data;
if (isBuf(data)) {
var placeholder = { _placeholder: true, num: buffers.length };
buffers.push(data);
return placeholder;
} else if (isArray(data)) {
var newData = new Array(data.length);
for (var i = 0; i < data.length; i++) {
newData[i] = _deconstructPacket(data[i]);
}
return newData;
} else if ('object' == typeof data && !(data instanceof Date)) {
var newData = {};
for (var key in data) {
newData[key] = _deconstructPacket(data[key]);
}
return newData;
if (isBuf(data)) {
var placeholder = { _placeholder: true, num: buffers.length };
buffers.push(data);
return placeholder;
} else if (isArray(data)) {
var newData = new Array(data.length);
for (var i = 0; i < data.length; i++) {
newData[i] = _deconstructPacket(data[i], buffers);
}
return data;
return newData;
} else if (typeof data === 'object' && !(data instanceof Date)) {
var newData = {};
for (var key in data) {
newData[key] = _deconstructPacket(data[key], buffers);
}
return newData;
}
return data;
}
var pack = packet;
pack.data = _deconstructPacket(packetData);
pack.attachments = buffers.length; // number of binary 'attachments'
return {packet: pack, buffers: buffers};
};
/**

@@ -64,26 +63,24 @@ * Reconstructs a binary packet from its placeholder packet and buffers

exports.reconstructPacket = function(packet, buffers) {
var curPlaceHolder = 0;
packet.data = _reconstructPacket(packet.data, buffers);
packet.attachments = undefined; // no longer useful
return packet;
};
function _reconstructPacket(data) {
if (data && data._placeholder) {
var buf = buffers[data.num]; // appropriate buffer (should be natural order anyway)
return buf;
} else if (isArray(data)) {
for (var i = 0; i < data.length; i++) {
data[i] = _reconstructPacket(data[i]);
}
return data;
} else if (data && 'object' == typeof data) {
for (var key in data) {
data[key] = _reconstructPacket(data[key]);
}
return data;
function _reconstructPacket(data, buffers) {
if (!data) return data;
if (data && data._placeholder) {
return buffers[data.num]; // appropriate buffer (should be natural order anyway)
} else if (isArray(data)) {
for (var i = 0; i < data.length; i++) {
data[i] = _reconstructPacket(data[i], buffers);
}
return data;
} else if (typeof data === 'object') {
for (var key in data) {
data[key] = _reconstructPacket(data[key], buffers);
}
}
packet.data = _reconstructPacket(packet.data);
packet.attachments = undefined; // no longer useful
return packet;
};
return data;
}

@@ -130,3 +127,3 @@ /**

}
} else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object
} else if (typeof obj === 'object' && !isBuf(obj)) { // and object
for (var key in obj) {

@@ -133,0 +130,0 @@ _removeBlobs(obj[key], key, obj);

2.3.2 / 2016-12-30
==================
* [perf] Small optimisations (#57)
* [chore] Update zuul config to speed up tests in browser (#58)
* [refactor] Remove useless variable (#55)
* [chore] Bump dependencies (#56)
* [refactor] Remove unused var (#53)
* [refactor] Use strict equality when possible (#52)
2.3.1 / 2016-10-24

@@ -3,0 +13,0 @@ ==================

@@ -129,3 +129,3 @@

if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
encodeAsBinary(obj, callback);

@@ -148,12 +148,9 @@ }

function encodeAsString(obj) {
var str = '';
var nsp = false;
// first is type
str += obj.type;
var str = '' + obj.type;
// attachments if we have them
if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
str += obj.attachments;
str += '-';
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
str += obj.attachments + '-';
}

@@ -163,5 +160,4 @@

// we append it followed by a comma `,`
if (obj.nsp && '/' != obj.nsp) {
nsp = true;
str += obj.nsp;
if (obj.nsp && '/' !== obj.nsp) {
str += obj.nsp + ',';
}

@@ -171,6 +167,2 @@

if (null != obj.id) {
if (nsp) {
str += ',';
nsp = false;
}
str += obj.id;

@@ -181,3 +173,2 @@ }

if (null != obj.data) {
if (nsp) str += ',';
str += json.stringify(obj.data);

@@ -241,5 +232,5 @@ }

var packet;
if ('string' == typeof obj) {
if (typeof obj === 'string') {
packet = decodeString(obj);
if (exports.BINARY_EVENT == packet.type || exports.BINARY_ACK == packet.type) { // binary packet's json
if (exports.BINARY_EVENT === packet.type || exports.BINARY_ACK === packet.type) { // binary packet's json
this.reconstructor = new BinaryReconstructor(packet);

@@ -280,17 +271,18 @@

function decodeString(str) {
var p = {};
var i = 0;
// look up type
var p = {
type: Number(str.charAt(0))
};
// look up type
p.type = Number(str.charAt(0));
if (null == exports.types[p.type]) return error();
// look up attachments if type binary
if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
if (exports.BINARY_EVENT === p.type || exports.BINARY_ACK === p.type) {
var buf = '';
while (str.charAt(++i) != '-') {
while (str.charAt(++i) !== '-') {
buf += str.charAt(i);
if (i == str.length) break;
}
if (buf != Number(buf) || str.charAt(i) != '-') {
if (buf != Number(buf) || str.charAt(i) !== '-') {
throw new Error('Illegal attachments');

@@ -302,9 +294,9 @@ }

// look up namespace (if any)
if ('/' == str.charAt(i + 1)) {
if ('/' === str.charAt(i + 1)) {
p.nsp = '';
while (++i) {
var c = str.charAt(i);
if (',' == c) break;
if (',' === c) break;
p.nsp += c;
if (i == str.length) break;
if (i === str.length) break;
}

@@ -326,3 +318,3 @@ } else {

p.id += str.charAt(i);
if (i == str.length) break;
if (i === str.length) break;
}

@@ -348,3 +340,3 @@ p.id = Number(p.id);

return p;
};
}

@@ -390,3 +382,3 @@ /**

this.buffers.push(binData);
if (this.buffers.length == this.reconPack.attachments) { // done with buffer list
if (this.buffers.length === this.reconPack.attachments) { // done with buffer list
var packet = binary.reconstructPacket(this.reconPack, this.buffers);

@@ -410,3 +402,3 @@ this.finishedReconstruction();

function error(data){
function error() {
return {

@@ -413,0 +405,0 @@ type: exports.ERROR,

{
"name": "socket.io-parser",
"version": "2.3.1",
"version": "2.3.2",
"description": "socket.io protocol parser",

@@ -15,12 +15,13 @@ "repository": {

"dependencies": {
"debug": "2.2.0",
"debug": "2.3.3",
"json3": "3.3.2",
"component-emitter": "1.1.2",
"component-emitter": "1.2.1",
"isarray": "0.0.1"
},
"devDependencies": {
"benchmark": "1.0.0",
"expect.js": "0.2.0",
"mocha": "1.16.2",
"zuul": "3.11.0",
"benchmark": "2.1.2",
"expect.js": "0.3.1",
"mocha": "3.2.0",
"socket.io-browsers": "^1.0.0",
"zuul": "3.11.1",
"zuul-ngrok": "4.0.0"

@@ -27,0 +28,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc