@@ -42,8 +42,8 @@ class Resp extends EventEmitter {
4242
4343 static encodeBufBulk ( buf ) {
4444 if ( ! Buffer . isBuffer ( buf ) ) throw new TypeError ( String ( buf ) + ' must be Buffer object' )
45- let prefix = '$' + buf . length + CRLF
46- let buffer = Buffer . allocUnsafe ( prefix . length + buf . length + 2 )
45+ const prefix = '$' + buf . length + CRLF
46+ const buffer = Buffer . allocUnsafe ( prefix . length + buf . length + 2 )
4747 buffer . write ( prefix )
4848 buf . copy ( buffer , prefix . length )
4949 buffer . write ( CRLF , prefix . length + buf . length )
@@ -52,9 +52,9 @@ class Resp extends EventEmitter {
5252
5353 static encodeArray ( arr ) {
5454 if ( ! Array . isArray ( arr ) ) throw new Error ( String ( arr ) + ' must be Array object' )
55- let prefix = '*' + arr . length + CRLF
55+ const prefix = '*' + arr . length + CRLF
5656 let length = prefix . length
57- let bufs = [ Buffer . from ( prefix ) ]
57+ const bufs = [ Buffer . from ( prefix ) ]
5858
5959 for ( let buf , i = 0 , len = arr . length ; i < len ; i ++ ) {
6060 buf = arr [ i ]
@@ -71,7 +71,7 @@ class Resp extends EventEmitter {
7171 if ( ! Array . isArray ( arr ) || arr . length === 0 ) {
7272 throw new Error ( String ( arr ) + ' must be array of value' )
7373 }
74- let bulks = Array ( arr . length )
74+ const bulks = Array ( arr . length )
7575 for ( let i = 0 , len = arr . length ; i < len ; i ++ ) {
7676 bulks [ i ] = Buffer . isBuffer ( arr [ i ] ) ? Resp . encodeBufBulk ( arr [ i ] ) : Resp . encodeBulk ( arr [ i ] )
7777 }
@@ -80,7 +80,7 @@ class Resp extends EventEmitter {
8080
8181 // Decode a RESP buffer to RESP value
8282 static decode ( buf , bufBulk ) {
83- let res = parseBuffer ( buf , 0 , bufBulk )
83+ const res = parseBuffer ( buf , 0 , bufBulk )
8484 if ( ! res || res . index < buf . length ) throw new Error ( 'Parse "' + buf + '" failed' )
8585 if ( res instanceof Error ) throw res
8686 return res . content
@@ -105,8 +105,8 @@ class Resp extends EventEmitter {
105105
106106 if ( ! this . _buf ) this . _buf = buf
107107 else {
108- let ret = this . _buf . length - this . _pos
109- let _buf = Buffer . allocUnsafe ( buf . length + ret )
108+ const ret = this . _buf . length - this . _pos
109+ const _buf = Buffer . allocUnsafe ( buf . length + ret )
110110
111111 this . _buf . copy ( _buf , 0 , this . _pos )
112112 buf . copy ( _buf , ret )
@@ -115,7 +115,7 @@ class Resp extends EventEmitter {
115115 }
116116
117117 while ( this . _pos < this . _buf . length ) {
118- let result = parseBuffer ( this . _buf , this . _pos , this . _bufBulk )
118+ const result = parseBuffer ( this . _buf , this . _pos , this . _bufBulk )
119119 if ( result == null ) {
120120 this . emit ( 'drain' )
121121 return true
@@ -153,8 +153,8 @@ class ReadRes {
153153}
154154
155155function readBuffer ( buf , i ) {
156- let start = i
157- let len = buf . length
156+ const start = i
157+ const len = buf . length
158158 while ( i < len && ! isCRLF ( buf , i ) ) i ++
159159 return i >= len ? null : new ReadRes ( buf . utf8Slice ( start , i ) , i + 2 )
160160}
@@ -190,7 +190,7 @@ function parseBuffer (buf, index, bufBulk) {
190190 if ( result == null ) return result
191191 num = parseInteger ( result . content )
192192 if ( num == null || num < - 1 ) return new Error ( 'Parse "$" failed, invalid length' )
193- let endIndex = result . index + num
193+ const endIndex = result . index + num
194194
195195 if ( num === - 1 ) {
196196 // Null Bulk
@@ -231,7 +231,7 @@ function parseBuffer (buf, index, bufBulk) {
231231}
232232
233233function parseInteger ( str ) {
234- let num = + str
234+ const num = + str
235235 return ( str && Number . isInteger ( num ) ) ? num : null
236236}
237237
0 commit comments