Last active
August 1, 2018 01:24
-
-
Save navio/cd5e8f91adbef54eaab07e280c3360de to your computer and use it in GitHub Desktop.
Copying data from a CSV to Another. π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Archivo | |
var stream = fs.createReadStream("fromDistributor.csv"); // Declarando Archivo a leer. | |
var writableStream = fs.createWriteStream("toShopify.csv"); // Declarando Archivo a crear y escribir. | |
// Stream Delcarations | |
var csvStream = csv.createWriteStream({headers: true}); // Creando flujo de datos y activando encabezado de columnas. | |
csvStream.pipe(writableStream); // Apropiando flujo de datos con objecto a escribir. | |
csv.fromStream(stream, {ignoreEmpty: true}) //leyendo del flujo de entrada. | |
.on("data", function(data){ // en linea leida. | |
csvStream.write({ // escribiendo nuevo linea en. | |
"columnName1": data[1], | |
"Column Name 2 with Spaces": data[2], | |
// agregar otras columnas..... Nombre de la columna: valor en la columna | |
}); | |
}) | |
.on("end", function(){ // al leer el evento de fin de archivo. | |
console.log("done"); | |
csvStream.end(); // cerrar el flujo de escrituro. | |
}); | |
writableStream.on("finish", function(){ // al cerrar el flujo de escritura | |
console.log("Done with file!"); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Si tienes dudas https://www.npmjs.com/package/fast-csv