Giter VIP home page Giter VIP logo

Comments (3)

dustinsmith1024 avatar dustinsmith1024 commented on August 16, 2024

Not totally sure. Most the examples have .pipe coming after .write.

There are tests for this so it should work in node 4 and 5 at least. https://github.com/C2FO/fast-csv/blob/master/test/formatting.test.js#L24

var ws = fs.createWriteStream("my.csv");
csv
   .write([
       {a: "a1", b: "b1"},
       {a: "a2", b: "b2"}
   ], {
        headers: true
        transform: function(row){
            return {
                A: row.a,
                B: row.b
            };
        }
   })
   .pipe(ws);

from fast-csv.

bllevy avatar bllevy commented on August 16, 2024

I'm running into this same problem working in node v6.1.0.

from fast-csv.

doug-martin avatar doug-martin commented on August 16, 2024

I think the two different write methods are being conflated. The write method in the inital example is the the write method that is provided by the node streams api, and should be called one row at a time.

The write report should be changed to.

function writeReport(file, data, cb){
    var existsAlready = fs.existsSync(file);
    var ws = fs.createWriteStream(file, {flags:'a'});
    var csvStream = csv.write(data, {
        headers: !existsAlready,
        includeEndRowDelimiter: true,
    });
    csvStream
        .on('finish', function(err){
            cb(err, file);
        })
        .pipe(fs.createWriteStream(file, {flags:'a'}));
}

from fast-csv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.