@@ -54,6 +54,11 @@ ReplyParser.prototype._parseResult = function (type) {
5454 throw new IncompleteReadBuffer ( "Wait for more data." ) ;
5555 }
5656
57+ if ( type === 45 ) {
58+ var result = this . _buffer . toString ( this . _encoding , start , end ) ;
59+ return new Error ( result ) ;
60+ }
61+
5762 if ( this . options . return_buffers ) {
5863 return this . _buffer . slice ( start , end ) ;
5964 } else {
@@ -76,12 +81,8 @@ ReplyParser.prototype._parseResult = function (type) {
7681 throw new IncompleteReadBuffer ( "Wait for more data." ) ;
7782 }
7883
79- if ( this . options . return_buffers ) {
80- return this . _buffer . slice ( start , end ) ;
81- }
82-
8384 // return the coerced numeric value
84- return + small_toString ( this . _buffer , start , end ) ;
85+ return + this . _buffer . toString ( 'ascii' , start , end ) ;
8586 } else if ( type === 36 ) { // $
8687 // set a rewind point, as the packet could be larger than the
8788 // buffer in memory
@@ -123,7 +124,7 @@ ReplyParser.prototype._parseResult = function (type) {
123124 throw new IncompleteReadBuffer ( "Wait for more data." ) ;
124125 }
125126
126- var reply = [ ] ;
127+ var reply = [ ] ;
127128 var ntype , i , res ;
128129
129130 offset = this . _offset - 1 ;
@@ -152,36 +153,25 @@ ReplyParser.prototype.execute = function (buffer) {
152153
153154 while ( true ) {
154155 offset = this . _offset ;
155- try {
156- // at least 4 bytes: :1\r\n
157- if ( this . _bytesRemaining ( ) < 4 ) {
158- break ;
159- }
156+ // at least 4 bytes: :1\r\n
157+ if ( this . _bytesRemaining ( ) < 4 ) {
158+ break ;
159+ }
160160
161+ try {
161162 type = this . _buffer [ this . _offset ++ ] ;
162163
163164 if ( type === 43 ) { // +
164165 ret = this . _parseResult ( type ) ;
165166
166- if ( ret === null ) {
167- break ;
168- }
169-
170167 this . send_reply ( ret ) ;
171168 } else if ( type === 45 ) { // -
172169 ret = this . _parseResult ( type ) ;
173170
174- if ( ret === null ) {
175- break ;
176- }
177- this . send_error ( new Error ( ret ) ) ;
171+ this . send_error ( ret ) ;
178172 } else if ( type === 58 ) { // :
179173 ret = this . _parseResult ( type ) ;
180174
181- if ( ret === null ) {
182- break ;
183- }
184-
185175 this . send_reply ( ret ) ;
186176 } else if ( type === 36 ) { // $
187177 ret = this . _parseResult ( type ) ;
@@ -219,9 +209,6 @@ ReplyParser.prototype.execute = function (buffer) {
219209} ;
220210
221211ReplyParser . prototype . append = function ( newBuffer ) {
222- if ( ! newBuffer ) {
223- return ;
224- }
225212
226213 // first run
227214 if ( this . _buffer === null ) {
@@ -238,27 +225,13 @@ ReplyParser.prototype.append = function (newBuffer) {
238225 return ;
239226 }
240227
241- // very large packet
242- // check for concat, if we have it, use it
243- if ( Buffer . concat !== undefined ) {
244- this . _buffer = Buffer . concat ( [ this . _buffer . slice ( this . _offset ) , newBuffer ] ) ;
245- } else {
246- var remaining = this . _bytesRemaining ( ) ,
247- newLength = remaining + newBuffer . length ,
248- tmpBuffer = new Buffer ( newLength ) ;
249-
250- this . _buffer . copy ( tmpBuffer , 0 , this . _offset ) ;
251- newBuffer . copy ( tmpBuffer , remaining , 0 ) ;
252-
253- this . _buffer = tmpBuffer ;
254- }
255-
228+ this . _buffer = Buffer . concat ( [ this . _buffer . slice ( this . _offset ) , newBuffer ] ) ;
256229 this . _offset = 0 ;
257230} ;
258231
259232ReplyParser . prototype . parseHeader = function ( ) {
260233 var end = this . _packetEndOffset ( ) ,
261- value = small_toString ( this . _buffer , this . _offset , end - 1 ) ;
234+ value = this . _buffer . toString ( 'ascii' , this . _offset , end - 1 ) ;
262235
263236 this . _offset = end + 1 ;
264237
@@ -270,10 +243,6 @@ ReplyParser.prototype._packetEndOffset = function () {
270243
271244 while ( this . _buffer [ offset ] !== 0x0d && this . _buffer [ offset + 1 ] !== 0x0a ) {
272245 offset ++ ;
273-
274- if ( offset >= this . _buffer . length ) {
275- throw new IncompleteReadBuffer ( "didn't see LF after NL reading multi bulk count (" + offset + " => " + this . _buffer . length + ", " + this . _offset + ")" ) ;
276- }
277246 }
278247
279248 offset ++ ;
0 commit comments