@@ -7,37 +7,21 @@ function Packet(type, size) {
77 this . size = + size ;
88}
99
10- exports . name = "javascript" ;
11-
12- function ReplyParser ( options ) {
10+ function ReplyParser ( return_buffers ) {
1311 this . name = exports . name ;
14- this . options = options ;
12+ this . return_buffers = return_buffers ;
1513
1614 this . _buffer = null ;
1715 this . _offset = 0 ;
1816 this . _encoding = "utf-8" ;
19- this . _reply_type = null ;
2017}
2118
22- exports . Parser = ReplyParser ;
23-
2419function IncompleteReadBuffer ( message ) {
2520 this . name = "IncompleteReadBuffer" ;
2621 this . message = message ;
2722}
2823util . inherits ( IncompleteReadBuffer , Error ) ;
2924
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-
4125ReplyParser . prototype . _parseResult = function ( type ) {
4226 var start , end , offset , packetHeader ;
4327
@@ -56,10 +40,8 @@ ReplyParser.prototype._parseResult = function (type) {
5640
5741 if ( type === 45 ) {
5842 return new Error ( this . _buffer . toString ( this . _encoding , start , end ) ) ;
59- } else if ( this . options . return_buffers ) {
43+ } else if ( this . return_buffers ) {
6044 return this . _buffer . slice ( start , end ) ;
61- } else if ( end - start < 65536 ) { // completely arbitrary
62- return small_toString ( this . _buffer , start , end ) ;
6345 }
6446 return this . _buffer . toString ( this . _encoding , start , end ) ;
6547 } else if ( type === 58 ) { // :
@@ -100,7 +82,7 @@ ReplyParser.prototype._parseResult = function (type) {
10082 throw new IncompleteReadBuffer ( "Wait for more data." ) ;
10183 }
10284
103- if ( this . options . return_buffers ) {
85+ if ( this . return_buffers ) {
10486 return this . _buffer . slice ( start , end ) ;
10587 }
10688 return this . _buffer . toString ( this . _encoding , start , end ) ;
@@ -234,3 +216,6 @@ ReplyParser.prototype._packetEndOffset = function () {
234216ReplyParser . prototype . _bytesRemaining = function ( ) {
235217 return ( this . _buffer . length - this . _offset ) < 0 ? 0 : ( this . _buffer . length - this . _offset ) ;
236218} ;
219+
220+ exports . Parser = ReplyParser ;
221+ exports . name = "javascript" ;
0 commit comments