@@ -8,6 +8,7 @@ var json = require('json3');
8
8
var isArray = require ( 'isarray' ) ;
9
9
var Emitter = require ( 'component-emitter' ) ;
10
10
var binary = require ( './binary' ) ;
11
+ var isBuf = require ( './is-buffer' ) ;
11
12
12
13
/**
13
14
* Protocol version.
@@ -89,14 +90,29 @@ exports.BINARY_EVENT = 5;
89
90
90
91
exports . BINARY_ACK = 6 ;
91
92
92
- exports . Encoder = Encoder
93
+ /**
94
+ * Encoder constructor.
95
+ *
96
+ * @api public
97
+ */
98
+
99
+ exports . Encoder = Encoder ;
100
+
101
+ /**
102
+ * Decoder constructor.
103
+ *
104
+ * @api public
105
+ */
106
+
107
+ exports . Decoder = Decoder ;
93
108
94
109
/**
95
110
* A socket.io Encoder instance
96
111
*
97
112
* @api public
98
113
*/
99
- function Encoder ( ) { } ;
114
+
115
+ function Encoder ( ) { }
100
116
101
117
/**
102
118
* Encode a packet as a single string if non-binary, or as a
@@ -191,8 +207,6 @@ function encodeAsBinary(obj, callback) {
191
207
binary . removeBlobs ( obj , writeEncoding ) ;
192
208
}
193
209
194
- exports . Decoder = Decoder
195
-
196
210
/**
197
211
* A socket.io Decoder instance
198
212
*
@@ -233,9 +247,7 @@ Decoder.prototype.add = function(obj) {
233
247
this . emit ( 'decoded' , packet ) ;
234
248
}
235
249
}
236
- else if ( ( global . Buffer && Buffer . isBuffer ( obj ) ) ||
237
- ( global . ArrayBuffer && obj instanceof ArrayBuffer ) ||
238
- obj . base64 ) { // raw binary data
250
+ else if ( isBuf ( obj ) || obj . base64 ) { // raw binary data
239
251
if ( ! this . reconstructor ) {
240
252
throw new Error ( 'got binary data when not reconstructing a packet' ) ;
241
253
} else {
@@ -249,7 +261,7 @@ Decoder.prototype.add = function(obj) {
249
261
else {
250
262
throw new Error ( 'Unknown type: ' + obj ) ;
251
263
}
252
- }
264
+ } ;
253
265
254
266
/**
255
267
* Decode a packet String (JSON data)
@@ -316,7 +328,7 @@ function decodeString(str) {
316
328
317
329
debug ( 'decoded %s as %j' , str , p ) ;
318
330
return p ;
319
- } ;
331
+ }
320
332
321
333
/**
322
334
* Deallocates a parser's resources
@@ -328,7 +340,7 @@ Decoder.prototype.destroy = function() {
328
340
if ( this . reconstructor ) {
329
341
this . reconstructor . finishedReconstruction ( ) ;
330
342
}
331
- }
343
+ } ;
332
344
333
345
/**
334
346
* A manager of a binary event's 'buffer sequence'. Should
@@ -363,7 +375,7 @@ BinaryReconstructor.prototype.takeBinaryData = function(binData) {
363
375
return packet ;
364
376
}
365
377
return null ;
366
- }
378
+ } ;
367
379
368
380
/**
369
381
* Cleans up binary packet reconstruction variables.
@@ -374,7 +386,7 @@ BinaryReconstructor.prototype.takeBinaryData = function(binData) {
374
386
BinaryReconstructor . prototype . finishedReconstruction = function ( ) {
375
387
this . reconPack = null ;
376
388
this . buffers = [ ] ;
377
- }
389
+ } ;
378
390
379
391
function error ( data ) {
380
392
return {
0 commit comments