engine.io-parser
Advanced tools
Comparing version 1.0.5 to 1.0.6
1.0.6 / 2014-05-30 | ||
================== | ||
* utf8 fixes when using binary encoding [nkzawa] | ||
1.0.5 / 2014-05-06 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -332,2 +332,32 @@ /** | ||
/** | ||
* | ||
* Converts a buffer to a utf8.js encoded string | ||
* | ||
* @api private | ||
*/ | ||
function bufferToString(buffer) { | ||
var str = ''; | ||
for (var i = 0; i < buffer.length; i++) { | ||
str += String.fromCharCode(buffer[i]); | ||
} | ||
return str; | ||
} | ||
/** | ||
* | ||
* Converts a utf8.js encoded string to a buffer | ||
* | ||
* @api private | ||
*/ | ||
function stringToBuffer(string) { | ||
var buf = new Buffer(string.length); | ||
for (var i = 0; i < string.length; i++) { | ||
buf.writeUInt8(string.charCodeAt(i), i); | ||
} | ||
return buf; | ||
} | ||
/** | ||
* Encodes multiple messages (payload) as binary. | ||
@@ -355,3 +385,3 @@ * | ||
if (typeof packet === 'string') { | ||
var encodingLength = '' + Buffer.byteLength(packet, "utf8"); | ||
var encodingLength = '' + packet.length; | ||
var sizeBuffer = new Buffer(encodingLength.length + 2); | ||
@@ -363,3 +393,3 @@ sizeBuffer[0] = 0; // is a string (not true binary = 0) | ||
sizeBuffer[sizeBuffer.length - 1] = 255; | ||
return doneCallback(null, Buffer.concat([sizeBuffer, new Buffer(packet, 'binary')])); | ||
return doneCallback(null, Buffer.concat([sizeBuffer, stringToBuffer(packet)])); | ||
} | ||
@@ -413,3 +443,3 @@ | ||
var msg = bufferTail.slice(1, msgLength + 1); | ||
if (isString) msg = msg.toString('binary'); | ||
if (isString) msg = bufferToString(msg); | ||
buffers.push(msg); | ||
@@ -416,0 +446,0 @@ bufferTail = bufferTail.slice(msgLength + 1); |
{ | ||
"name": "engine.io-parser", | ||
"description": "Parser for the client for the realtime Engine", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"homepage": "https://github.com/LearnBoost/engine.io-protocol", | ||
@@ -6,0 +6,0 @@ "devDependencies": { |
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
28530
839