From 074dfe2e7e7a0f2f6e5af7bc79e585a7c610eaf8 Mon Sep 17 00:00:00 2001 From: Peter van Gulik Date: Thu, 28 Dec 2023 17:34:01 +0100 Subject: [PATCH] fix: ingest job doesn't properly validate `chunkDataSize` causing it to exceeds the API limit --- packages/salesforce/src/bulk/bulkIngestJob.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/salesforce/src/bulk/bulkIngestJob.ts b/packages/salesforce/src/bulk/bulkIngestJob.ts index 701c193d..f682d048 100644 --- a/packages/salesforce/src/bulk/bulkIngestJob.ts +++ b/packages/salesforce/src/bulk/bulkIngestJob.ts @@ -276,14 +276,16 @@ export class BulkIngestJob extends BulkJob this.encodeValue(item[c])).join(this.delimiterCharacter) + this.lineEndingCharacters; const encodedRow = Buffer.from(row, this.encoding); - encodedData.push(encodedRow); - if (encodedDataSize + encodedRow.byteLength > this.chunkDataSize) { + if (encodedData.length > 1 && (encodedDataSize + encodedRow.byteLength) > this.chunkDataSize) { const chunk = Buffer.concat(encodedData); encodedData = [ encodedHeader ]; encodedDataSize = encodedHeader.byteLength; yield chunk; } + + encodedData.push(encodedRow); + encodedDataSize += encodedRow.byteLength; } if (encodedData.length > 1) {