@@ -7,37 +7,21 @@ function Packet(type, size) {
7
7
this . size = + size ;
8
8
}
9
9
10
- exports . name = "javascript" ;
11
-
12
- function ReplyParser ( options ) {
10
+ function ReplyParser ( return_buffers ) {
13
11
this . name = exports . name ;
14
- this . options = options ;
12
+ this . return_buffers = return_buffers ;
15
13
16
14
this . _buffer = null ;
17
15
this . _offset = 0 ;
18
16
this . _encoding = "utf-8" ;
19
- this . _reply_type = null ;
20
17
}
21
18
22
- exports . Parser = ReplyParser ;
23
-
24
19
function IncompleteReadBuffer ( message ) {
25
20
this . name = "IncompleteReadBuffer" ;
26
21
this . message = message ;
27
22
}
28
23
util . inherits ( IncompleteReadBuffer , Error ) ;
29
24
30
- // Buffer.toString() is quite slow for small strings
31
- function small_toString ( buf , start , end ) {
32
- var tmp = "" , i ;
33
-
34
- for ( i = start ; i < end ; i ++ ) {
35
- tmp += String . fromCharCode ( buf [ i ] ) ;
36
- }
37
-
38
- return tmp ;
39
- }
40
-
41
25
ReplyParser . prototype . _parseResult = function ( type ) {
42
26
var start , end , offset , packetHeader ;
43
27
@@ -56,10 +40,8 @@ ReplyParser.prototype._parseResult = function (type) {
56
40
57
41
if ( type === 45 ) {
58
42
return new Error ( this . _buffer . toString ( this . _encoding , start , end ) ) ;
59
- } else if ( this . options . return_buffers ) {
43
+ } else if ( this . return_buffers ) {
60
44
return this . _buffer . slice ( start , end ) ;
61
- } else if ( end - start < 65536 ) { // completely arbitrary
62
- return small_toString ( this . _buffer , start , end ) ;
63
45
}
64
46
return this . _buffer . toString ( this . _encoding , start , end ) ;
65
47
} else if ( type === 58 ) { // :
@@ -100,7 +82,7 @@ ReplyParser.prototype._parseResult = function (type) {
100
82
throw new IncompleteReadBuffer ( "Wait for more data." ) ;
101
83
}
102
84
103
- if ( this . options . return_buffers ) {
85
+ if ( this . return_buffers ) {
104
86
return this . _buffer . slice ( start , end ) ;
105
87
}
106
88
return this . _buffer . toString ( this . _encoding , start , end ) ;
@@ -234,3 +216,6 @@ ReplyParser.prototype._packetEndOffset = function () {
234
216
ReplyParser . prototype . _bytesRemaining = function ( ) {
235
217
return ( this . _buffer . length - this . _offset ) < 0 ? 0 : ( this . _buffer . length - this . _offset ) ;
236
218
} ;
219
+
220
+ exports . Parser = ReplyParser ;
221
+ exports . name = "javascript" ;
0 commit comments