File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ function Connection(options = {}) {
3333 let next = false
3434 let statements = { }
3535 let connect_timer
36+ let buffers = null
37+ let remaining = 0
3638
3739 const queries = Queue ( )
3840 , id = count ++
@@ -285,17 +287,31 @@ function Connection(options = {}) {
285287 }
286288
287289 function data ( x ) {
288- buffer = buffer . length === 0
289- ? x
290- : Buffer . concat ( [ buffer , x ] , buffer . length + x . length )
290+ if ( buffers ) {
291+ buffers . push ( x )
292+ remaining -= x . length
293+ if ( remaining >= 0 )
294+ return
295+ }
296+
297+ buffer = buffers
298+ ? Buffer . concat ( buffers , length - remaining )
299+ : buffer . length === 0
300+ ? x
301+ : Buffer . concat ( [ buffer , x ] , buffer . length + x . length )
291302
292303 while ( buffer . length > 4 ) {
293304 length = buffer . readInt32BE ( 1 )
294- if ( length >= buffer . length )
305+ if ( length >= buffer . length ) {
306+ remaining = length - buffer . length
307+ buffers = [ buffer ]
295308 break
309+ }
296310
297311 backend [ buffer [ 0 ] ] ( buffer . slice ( 0 , length + 1 ) )
298312 buffer = buffer . slice ( length + 1 )
313+ remaining = 0
314+ buffers = null
299315 }
300316 }
301317
You can’t perform that action at this time.
0 commit comments