From ab2c8aad350ae820f5a39a61cd205fa5df99c080 Mon Sep 17 00:00:00 2001 From: Siting Ren Date: Wed, 29 May 2024 10:19:40 +0800 Subject: [PATCH] Fix copy local reject files larger than buffer size (#147) --- packages/vertica-nodejs/lib/query.js | 2 +- .../mochatest/integration/client/copy-local-file-tests.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vertica-nodejs/lib/query.js b/packages/vertica-nodejs/lib/query.js index 2026e458..a18a2234 100644 --- a/packages/vertica-nodejs/lib/query.js +++ b/packages/vertica-nodejs/lib/query.js @@ -337,7 +337,7 @@ class Query extends EventEmitter { if (msg.fileName.length === 0) { //using returnrejected, fileContents is an array of row numbers, not a string this._result._setRejectedRows(msg.fileContents) } else { // future enhancement, move file IO to util - fs.appendFile(msg.fileName, msg.fileContents, (err) => { + fs.appendFileSync(msg.fileName, msg.fileContents, (err) => { if (err) { console.error('Error writing to file:', err); } diff --git a/packages/vertica-nodejs/mochatest/integration/client/copy-local-file-tests.js b/packages/vertica-nodejs/mochatest/integration/client/copy-local-file-tests.js index 67a118aa..6a3fcc8b 100644 --- a/packages/vertica-nodejs/mochatest/integration/client/copy-local-file-tests.js +++ b/packages/vertica-nodejs/mochatest/integration/client/copy-local-file-tests.js @@ -175,8 +175,10 @@ describe('Running Copy From Local File Commands', function () { fs.stat('rejects-large.txt', (statErr, stats) => { assert.equal(statErr, null); - assert.equal(stats.size, 98894); }); + var inputBuf = fs.readFileSync('large-copy-bad.dat'); + var rejectBuf = fs.readFileSync('rejects-large.txt'); + assert(inputBuf.equals(rejectBuf), 'content in rejected data file is not the same as the input file') } finally { fs.unlink('large-copy-bad.dat', () => { fs.unlink('rejects-large.txt', done)