I have the folllowing code which opens a directory, reads each csv file in it and creates a stream:
var files = fs.readdirSync('./dir/');
for (var i in files) {
var stream = fs.createReadStream('./dir/' + files[i]);
stream.on('data', function(data) {
console.log(data);
});
}
I can see that the console.log prints out binary data that looks like so:
<Buffer 22 50 52 30 20 32 41 41 22 2c 35 30 2c 33 35 35 30 30 38 2c 34 32 39 33 37 38 2c 22 45 39 32 30 30 30 30 30 31 22>
How can I use this to parse my csv file line by line?
I've managed to get the data back using toString():
console.log(data.toString());
but fairly sure this isn't the route I need to go.
I want to be able to extract the first entry for each line in the csv.