Skip to content

Commit

Permalink
fix: Wait for CSV file stream
Browse files Browse the repository at this point in the history
* Stream behaviour was introduced with forcedotcom#617
* We have been waiting for the csvTransformStream only
* FileStream was not fully flushed so we missed CSV records forcedotcom#618
  • Loading branch information
R0Wi-KS committed Aug 1, 2023
1 parent 16da2b5 commit 4122f1a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/modules/components/common_components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -868,18 +868,21 @@ export class Common {
}
}

const fileStream = fs.createWriteStream(filePath);
const csvTransformStream = new CsvTransformStream();
csvTransformStream.pipe(fs.createWriteStream(filePath));

csvTransformStream.pipe(fileStream);

for(const record of array) {
csvTransformStream.write(record);
}

csvTransformStream.end();

// Wait for file to be fully written #618
return new Promise((resolve, reject) => {
csvTransformStream.on('finish', resolve)
csvTransformStream.on('error', reject)
fileStream.on('finish', resolve);
fileStream.on('error', reject);
})
} catch (ex) {
throw new CommandExecutionError(this.logger.getResourceString(RESOURCES.writingCsvFileError, filePath, ex.message));
Expand Down

0 comments on commit 4122f1a

Please sign in to comment.