I love your parser and I usually parse around 500K lines of CSV files. While this does well, I often noticed that during parsing, I run out of memory. The original code stored all records in array. I was wondering if I could just pause after say 500 entries in array and sleep for few a while before proceeding? This would give a chance for garbage collector to clean up some older objects for this to continue. Is this possible?
log("[parse_csv_internal_csv_stream]:Parsing CSV internal csv starts", 7, conductor_log_modules.csv_functions);
var finalData = [];
var readStream = fs.createReadStream(parseFile);
var parser = csv.parse({columns: true, relax: true});
readStream.on('open', function () {
// This just pipes the read stream to the response object (which goes to the client)
readStream.pipe(parser);
});
readStream.on('error', function(err) {
log(err.message, 3, conductor_log_modules.csv_functions);
onComplete(err, null);
});
parser.on('readable', function(){
while(record = parser.read()){
finalData.push(record);
}
});
// Catch any error
parser.on('error', function(err) {
log(err.message, 3, conductor_log_modules.csv_functions);
onComplete(err, null);
});
parser.on('finish', function () {
log("[parse_csv_internal_csv_stream]:Parsing CSV internal csv ends", 7, conductor_log_modules.csv_functions);
onComplete(null, finalData);
parser.end();
});