We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm trying to add an extra column to a csv file and would like to do this via streams utilising a pipe. This is what I have so far:
var fs = require('fs'); var csv = require("fast-csv"); var input = fs.createReadStream("input.csv"); var output = fs.createWriteStream("output.csv", {encoding: 'utf-8'}); var count = 1; var csvStream = csv({rtrim: true, headers: true}) .on("record", function(data){ data.ordinalValue = count; count = count + 1; }) .on("end", function(){ console.log("done"); }); input.pipe(csvStream).pipe(output);
It just puts a stringified JSON object though..
The text was updated successfully, but these errors were encountered:
So, we had to do something similar, and with the latest version of fast-csv this is possible.
fast-csv
var fs = require('fs'); var csv = require("fast-csv"); var count = 1; var csvOutputStream = csv.createWriteStream({rtrim: true, headers: true}); var output = csvOutputStream .pipe(fs.createWriteStream("output.csv", {encoding: 'utf-8'})) .on("finish", function () { console.log("done"); }); csv.fromPath("input.csv", {rtrim: true, headers: true}) .on("record", function (data) { data.ordinalValue = count; count = count + 1; csvOutputStream.write(data); }) .on("end", function () { csvOutputStream.write(null); });
Sorry, something went wrong.
Fix C2FO#28
b43d85c
No branches or pull requests
I'm trying to add an extra column to a csv file and would like to do this via streams utilising a pipe. This is what I have so far:
It just puts a stringified JSON object though..
The text was updated successfully, but these errors were encountered: