Skip to content

Commit f44256c

Browse files
authoredApr 24, 2017
[feat] Move binary detection to the parser (#66)
1 parent 817adca commit f44256c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
 

‎index.js

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
var debug = require('debug')('socket.io-parser');
77
var Emitter = require('component-emitter');
8+
var hasBin = require('has-binary2');
89
var binary = require('./binary');
910
var isBuf = require('./is-buffer');
1011

@@ -123,6 +124,10 @@ function Encoder() {}
123124
*/
124125

125126
Encoder.prototype.encode = function(obj, callback){
127+
if ((obj.type === exports.EVENT || obj.type === exports.ACK) && hasBin(obj.data)) {
128+
obj.type = obj.type === exports.EVENT ? exports.BINARY_EVENT : exports.BINARY_ACK;
129+
}
130+
126131
debug('encoding packet %j', obj);
127132

128133
if (exports.BINARY_EVENT === obj.type || exports.BINARY_ACK === obj.type) {

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies": {
1515
"debug": "2.3.3",
1616
"component-emitter": "1.2.1",
17+
"has-binary2": "1.0.1",
1718
"isarray": "2.0.1"
1819
},
1920
"devDependencies": {

0 commit comments

Comments
 (0)
Please sign in to comment.