engine.io-parser
Advanced tools
Comparing version 1.2.3 to 1.2.4
1.2.4 / 2015-12-04 | ||
================== | ||
* fix `ArrayBuffer` encoding in base64 string | ||
1.2.3 / 2015-11-28 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -66,3 +66,4 @@ /** | ||
} else if (packet.data && (packet.data.buffer || packet.data) instanceof ArrayBuffer) { | ||
return encodeArrayBuffer(packet, supportsBinary, callback); | ||
packet.data = arrayBufferToBuffer(packet.data); | ||
return encodeBuffer(packet, supportsBinary, callback); | ||
} | ||
@@ -96,20 +97,2 @@ | ||
function encodeArrayBuffer(packet, supportsBinary, callback) { | ||
var data = packet.data.buffer || packet.data; | ||
if (!supportsBinary) { | ||
return exports.encodeBase64Packet(packet, callback); | ||
} | ||
var contentArray = new Uint8Array(data); | ||
var resultBuffer = new Buffer(1 + data.byteLength); | ||
resultBuffer[0] = packets[packet.type]; | ||
for (var i = 0; i < contentArray.length; i++){ | ||
resultBuffer[i+1] = contentArray[i]; | ||
} | ||
return callback(resultBuffer); | ||
} | ||
/** | ||
@@ -123,9 +106,4 @@ * Encodes a packet with binary data in a base64 string | ||
exports.encodeBase64Packet = function(packet, callback){ | ||
if (!Buffer.isBuffer(packet.data)) { | ||
var buf = new Buffer(packet.data.byteLength); | ||
for (var i = 0; i < buf.length; i++) { | ||
buf[i] = packet.data[i]; | ||
} | ||
packet.data = buf; | ||
packet.data = arrayBufferToBuffer(packet.data); | ||
} | ||
@@ -371,2 +349,22 @@ | ||
/** | ||
* | ||
* Converts an ArrayBuffer to a Buffer | ||
* | ||
* @api private | ||
*/ | ||
function arrayBufferToBuffer(data) { | ||
// data is either an ArrayBuffer or ArrayBufferView. | ||
var array = new Uint8Array(data.buffer || data); | ||
var length = data.byteLength || data.length; | ||
var offset = data.byteOffset || 0; | ||
var buffer = new Buffer(length); | ||
for (var i = 0; i < length; i++) { | ||
buffer[i] = array[offset + i]; | ||
} | ||
return buffer; | ||
} | ||
/** | ||
* Encodes multiple messages (payload) as binary. | ||
@@ -373,0 +371,0 @@ * |
{ | ||
"name": "engine.io-parser", | ||
"description": "Parser for the client for the realtime Engine", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"homepage": "https://github.com/Automattic/engine.io-parser", | ||
@@ -6,0 +6,0 @@ "devDependencies": { |
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
890
37943