engine.io-parser
Advanced tools
Comparing version 1.0.8 to 1.1.0
1.1.0 / 2014-07-16 | ||
================== | ||
* make utf8 encoding/decoding optional | ||
1.0.8 / 2014-07-16 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -70,4 +70,4 @@ /** | ||
exports.encodePacket = function (packet, supportsBinary, callback) { | ||
if (typeof supportsBinary == 'function') { | ||
exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) { | ||
if ('function' == typeof supportsBinary) { | ||
callback = supportsBinary; | ||
@@ -77,2 +77,7 @@ supportsBinary = false; | ||
if ('function' == typeof utf8encode) { | ||
callback = utf8encode; | ||
utf8encode = null; | ||
} | ||
var data = (packet.data === undefined) | ||
@@ -93,3 +98,3 @@ ? undefined | ||
if (undefined !== packet.data) { | ||
encoded += utf8.encode(String(packet.data)); | ||
encoded += utf8encode ? utf8.encode(String(packet.data)) : String(packet.data); | ||
} | ||
@@ -130,3 +135,3 @@ | ||
packet.data = fr.result; | ||
exports.encodePacket(packet, supportsBinary, callback); | ||
exports.encodePacket(packet, supportsBinary, true, callback); | ||
}; | ||
@@ -193,3 +198,3 @@ return fr.readAsArrayBuffer(packet.data); | ||
exports.decodePacket = function (data, binaryType) { | ||
exports.decodePacket = function (data, binaryType, utf8decode) { | ||
// String data | ||
@@ -201,6 +206,8 @@ if (typeof data == 'string' || data === undefined) { | ||
try { | ||
data = utf8.decode(data); | ||
} catch (e) { | ||
return err; | ||
if (utf8decode) { | ||
try { | ||
data = utf8.decode(data); | ||
} catch (e) { | ||
return err; | ||
} | ||
} | ||
@@ -290,3 +297,3 @@ var type = data.charAt(0); | ||
function encodeOne(packet, doneCallback) { | ||
exports.encodePacket(packet, supportsBinary, function(message) { | ||
exports.encodePacket(packet, supportsBinary, true, function(message) { | ||
doneCallback(null, setLengthHeader(message)); | ||
@@ -367,3 +374,3 @@ }); | ||
if (msg.length) { | ||
packet = exports.decodePacket(msg, binaryType); | ||
packet = exports.decodePacket(msg, binaryType, true); | ||
@@ -412,3 +419,3 @@ if (err.type == packet.type && err.data == packet.data) { | ||
function encodeOne(packet, doneCallback) { | ||
exports.encodePacket(packet, true, function(data) { | ||
exports.encodePacket(packet, true, true, function(data) { | ||
return doneCallback(null, data); | ||
@@ -471,3 +478,3 @@ }); | ||
function encodeOne(packet, doneCallback) { | ||
exports.encodePacket(packet, true, function(encoded) { | ||
exports.encodePacket(packet, true, true, function(encoded) { | ||
var binaryIdentifier = new Uint8Array(1); | ||
@@ -567,4 +574,4 @@ binaryIdentifier[0] = 1; | ||
buffers.forEach(function(buffer, i) { | ||
callback(exports.decodePacket(buffer, binaryType), i, total); | ||
callback(exports.decodePacket(buffer, binaryType, true), i, total); | ||
}); | ||
}; |
@@ -52,4 +52,4 @@ /** | ||
exports.encodePacket = function (packet, supportsBinary, callback) { | ||
if (typeof supportsBinary == 'function') { | ||
exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) { | ||
if ('function' == typeof supportsBinary) { | ||
callback = supportsBinary; | ||
@@ -59,2 +59,7 @@ supportsBinary = null; | ||
if ('function' == typeof utf8encode ) { | ||
callback = utf8encode; | ||
utf8encode = null; | ||
} | ||
var data = (packet.data === undefined) | ||
@@ -75,3 +80,3 @@ ? undefined | ||
if (undefined !== packet.data) { | ||
encoded += utf8.encode(String(packet.data)); | ||
encoded += utf8encode ? utf8.encode(String(packet.data)) : String(packet.data); | ||
} | ||
@@ -145,3 +150,3 @@ | ||
exports.decodePacket = function (data, binaryType) { | ||
exports.decodePacket = function (data, binaryType, utf8decode) { | ||
// String data | ||
@@ -154,6 +159,8 @@ if (typeof data == 'string' || data === undefined) { | ||
var type = data.charAt(0); | ||
try { | ||
data = utf8.decode(data); | ||
} catch (e) { | ||
return err; | ||
if (utf8decode) { | ||
try { | ||
data = utf8.decode(data); | ||
} catch (e) { | ||
return err; | ||
} | ||
} | ||
@@ -240,3 +247,3 @@ | ||
function encodeOne(packet, doneCallback) { | ||
exports.encodePacket(packet, supportsBinary, function(message) { | ||
exports.encodePacket(packet, supportsBinary, true, function(message) { | ||
doneCallback(null, setLengthHeader(message)); | ||
@@ -317,3 +324,3 @@ }); | ||
if (msg.length) { | ||
packet = exports.decodePacket(msg, binaryType); | ||
packet = exports.decodePacket(msg, binaryType, true); | ||
@@ -392,3 +399,3 @@ if (err.type == packet.type && err.data == packet.data) { | ||
function encodeOne(p, doneCallback) { | ||
exports.encodePacket(p, true, function(packet) { | ||
exports.encodePacket(p, true, true, function(packet) { | ||
@@ -466,4 +473,4 @@ if (typeof packet === 'string') { | ||
buffers.forEach(function(buffer, i) { | ||
callback(exports.decodePacket(buffer, binaryType), i, total); | ||
callback(exports.decodePacket(buffer, binaryType, true), i, total); | ||
}); | ||
}; |
{ | ||
"name": "engine.io-parser", | ||
"description": "Parser for the client for the realtime Engine", | ||
"version": "1.0.8", | ||
"version": "1.1.0", | ||
"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
29801
872