Merge pull request #53 from jeromew/upstream-frontier
Bugfix - wrong tests on chunk frontiers
This commit is contained in:
commit
f29aef3bba
@ -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)
|
||||
|
@ -7,6 +7,7 @@ var concat = require('concat-stream')
|
||||
var pg = require('pg')
|
||||
|
||||
var copy = require('../').to
|
||||
var code = require('../message-formats')
|
||||
|
||||
var client = function() {
|
||||
var client = new pg.Client()
|
||||
@ -22,6 +23,18 @@ var testConstruction = function() {
|
||||
|
||||
testConstruction()
|
||||
|
||||
var testComparators = function() {
|
||||
var copy1 = copy();
|
||||
copy1.pipe(concat(function(buf) {
|
||||
assert(copy1._gotCopyOutResponse, 'should have received CopyOutResponse')
|
||||
assert(!copy1._remainder, 'Message with no additional data (len=Int4Len+0) should not leave a remainder')
|
||||
}))
|
||||
copy1.end(new Buffer([code.CopyOutResponse, 0x00, 0x00, 0x00, 0x04]));
|
||||
|
||||
|
||||
}
|
||||
testComparators();
|
||||
|
||||
var testRange = function(top) {
|
||||
var fromClient = client()
|
||||
var txt = 'COPY (SELECT * from generate_series(0, ' + (top - 1) + ')) TO STDOUT'
|
||||
|
Loading…
Reference in New Issue
Block a user