socket.io-parser
Advanced tools
Comparing version 2.2.1 to 2.2.2
113
binary.js
@@ -0,6 +1,9 @@ | ||
/*global Blob,File*/ | ||
/** | ||
* Modle requirements | ||
* Module requirements | ||
*/ | ||
var isArray = require('isarray'); | ||
var isBuf = require('./is-buffer'); | ||
@@ -17,35 +20,34 @@ /** | ||
exports.deconstructPacket = function(packet) { | ||
var buffers = []; | ||
var packetData = packet.data; | ||
exports.deconstructPacket = function(packet){ | ||
var buffers = []; | ||
var packetData = packet.data; | ||
function _deconstructPacket(data) { | ||
if (!data) return data; | ||
function _deconstructPacket(data) { | ||
if (!data) return data; | ||
if ((global.Buffer && Buffer.isBuffer(data)) || | ||
(global.ArrayBuffer && data instanceof ArrayBuffer)) { // replace binary | ||
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]); | ||
} | ||
return data; | ||
return newData; | ||
} else if ('object' == typeof data && !(data instanceof Date)) { | ||
var newData = {}; | ||
for (var key in data) { | ||
newData[key] = _deconstructPacket(data[key]); | ||
} | ||
return newData; | ||
} | ||
return data; | ||
} | ||
var pack = packet; | ||
pack.data = _deconstructPacket(packetData); | ||
pack.attachments = buffers.length; // number of binary 'attachments' | ||
return {packet: pack, buffers: buffers}; | ||
} | ||
var pack = packet; | ||
pack.data = _deconstructPacket(packetData); | ||
pack.attachments = buffers.length; // number of binary 'attachments' | ||
return {packet: pack, buffers: buffers}; | ||
}; | ||
@@ -61,27 +63,27 @@ /** | ||
exports.reconstructPacket = function(packet, buffers) { | ||
var curPlaceHolder = 0; | ||
exports.reconstructPacket = function(packet, buffers) { | ||
var curPlaceHolder = 0; | ||
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) { | ||
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; | ||
} | ||
return data; | ||
} | ||
packet.data = _reconstructPacket(packet.data); | ||
packet.attachments = undefined; // no longer useful | ||
return packet; | ||
} | ||
packet.data = _reconstructPacket(packet.data); | ||
packet.attachments = undefined; // no longer useful | ||
return packet; | ||
}; | ||
@@ -99,3 +101,2 @@ /** | ||
exports.removeBlobs = function(data, callback) { | ||
function _removeBlobs(obj, curKey, containingObject) { | ||
@@ -143,12 +144,2 @@ if (!obj) return obj; | ||
} | ||
} | ||
/** | ||
* Returns true if obj is a buffer or an arraybuffer. | ||
* | ||
* @api private | ||
*/ | ||
function isBuf(obj) { | ||
return (global.Buffer && Buffer.isBuffer(obj)) || | ||
(global.ArrayBuffer && obj instanceof ArrayBuffer); | ||
} | ||
}; |
2.2.2 / 2014-09-04 | ||
================== | ||
* prevent direct `Buffer` reference that breaks browserify | ||
* binary: reuse `isBuf` helper | ||
2.2.1 / 2014-06-20 | ||
@@ -3,0 +9,0 @@ ================== |
36
index.js
@@ -11,2 +11,3 @@ | ||
var binary = require('./binary'); | ||
var isBuf = require('./is-buffer'); | ||
@@ -93,5 +94,19 @@ /** | ||
exports.Encoder = Encoder | ||
/** | ||
* Encoder constructor. | ||
* | ||
* @api public | ||
*/ | ||
exports.Encoder = Encoder; | ||
/** | ||
* Decoder constructor. | ||
* | ||
* @api public | ||
*/ | ||
exports.Decoder = Decoder; | ||
/** | ||
* A socket.io Encoder instance | ||
@@ -101,4 +116,5 @@ * | ||
*/ | ||
function Encoder() {}; | ||
function Encoder() {} | ||
/** | ||
@@ -197,4 +213,2 @@ * Encode a packet as a single string if non-binary, or as a | ||
exports.Decoder = Decoder | ||
/** | ||
@@ -240,5 +254,3 @@ * A socket.io Decoder instance | ||
} | ||
else if ((global.Buffer && Buffer.isBuffer(obj)) || | ||
(global.ArrayBuffer && obj instanceof ArrayBuffer) || | ||
obj.base64) { // raw binary data | ||
else if (isBuf(obj) || obj.base64) { // raw binary data | ||
if (!this.reconstructor) { | ||
@@ -257,3 +269,3 @@ throw new Error('got binary data when not reconstructing a packet'); | ||
} | ||
} | ||
}; | ||
@@ -325,3 +337,3 @@ /** | ||
return p; | ||
}; | ||
} | ||
@@ -338,3 +350,3 @@ /** | ||
} | ||
} | ||
}; | ||
@@ -374,3 +386,3 @@ /** | ||
return null; | ||
} | ||
}; | ||
@@ -386,3 +398,3 @@ /** | ||
this.buffers = []; | ||
} | ||
}; | ||
@@ -389,0 +401,0 @@ function error(data){ |
{ | ||
"name": "socket.io-parser", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "socket.io protocol parser", | ||
@@ -5,0 +5,0 @@ "repository": { |
# socket.io-parser | ||
[![Build Status](https://secure.travis-ci.org/Automattic/socket.io-parser.png)](http://travis-ci.org/Automattic/socket.io-parser) | ||
[![NPM version](https://badge.fury.io/js/socket.io-parser.png)](http://badge.fury.io/js/socket.io-parser) | ||
[![Build Status](https://secure.travis-ci.org/Automattic/socket.io-parser.svg)](http://travis-ci.org/Automattic/socket.io-parser) | ||
[![NPM version](https://badge.fury.io/js/socket.io-parser.svg)](http://badge.fury.io/js/socket.io-parser) | ||
@@ -7,0 +7,0 @@ A socket.io encoder and decoder written in JavaScript complying with version `3` |
Sorry, the diff of this file is not supported yet
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
18951
12
546