From 9ccda040365ad2a83df68d533ddf65e317e64e3b Mon Sep 17 00:00:00 2001 From: jeromew Date: Thu, 28 Jul 2016 23:03:11 +0000 Subject: [PATCH] Bugfix - Chunk frontiers were not correctly tested --- copy-to.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/copy-to.js b/copy-to.js index 716a072..a45ee6e 100644 --- a/copy-to.js +++ b/copy-to.js @@ -42,10 +42,10 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { var messageCode; var needPush = false; - while((chunk.length - offset) > (Byte1Len + Int32Len)) { + while((chunk.length - offset) >= (Byte1Len + Int32Len)) { var messageCode = chunk[offset] - //console.log(c, w, offset, 'PostgreSQL message ' + String.fromCharCode(messageCode)) + //console.log('PostgreSQL message ' + String.fromCharCode(messageCode)) switch(messageCode) { // detect COPY start @@ -79,7 +79,7 @@ CopyStreamQuery.prototype._transform = function(chunk, enc, cb) { } length = chunk.readUInt32BE(offset+Byte1Len) - if(chunk.length > (offset + Byte1Len + length)) { + if(chunk.length >= (offset + Byte1Len + length)) { offset += Byte1Len + Int32Len if (needPush) { var row = chunk.slice(offset, offset + length - Int32Len)