Skip to content

Commit

Permalink
[feat] Move binary detection to the parser (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 24, 2017
1 parent 817adca commit f44256c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Expand Up @@ -5,6 +5,7 @@

var debug = require('debug')('socket.io-parser');
var Emitter = require('component-emitter');
var hasBin = require('has-binary2');
var binary = require('./binary');
var isBuf = require('./is-buffer');

Expand Down Expand Up @@ -123,6 +124,10 @@ function Encoder() {}
*/

Encoder.prototype.encode = function(obj, callback){
if ((obj.type === exports.EVENT || obj.type === exports.ACK) && hasBin(obj.data)) {
obj.type = obj.type === exports.EVENT ? exports.BINARY_EVENT : exports.BINARY_ACK;
}

debug('encoding packet %j', obj);

if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"debug": "2.3.3",
"component-emitter": "1.2.1",
"has-binary2": "1.0.1",
"isarray": "2.0.1"
},
"devDependencies": {
Expand Down

0 comments on commit f44256c

Please sign in to comment.