Skip to content

Instantly share code, notes, and snippets.

@natpen
Created July 29, 2015 17:52
Show Gist options
  • Select an option

  • Save natpen/9ea5e5c7b7ad94e8bd8b to your computer and use it in GitHub Desktop.

Select an option

Save natpen/9ea5e5c7b7ad94e8bd8b to your computer and use it in GitHub Desktop.

Revisions

  1. natpen created this gist Jul 29, 2015.
    34 changes: 34 additions & 0 deletions nodeStreamConfusion.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    var extend = require('extend');
    var spawn = require('child_process').spawn;
    var csv = require('csv');

    var ls = spawn('git', ['log']);

    ls.stdout.on('data', function (data) {
    parser.write(data);
    });

    ls.on('close', function (code) {
    // parser.end(); // either I call parser.end() explicitly and it
    // gets called before readable work finishes, or it
    // never gets called at all
    console.log('exit code ' + code);
    });

    var parser = csv.parse({delimiter: '\t'});

    parser.on('readable', function() {
    while(data = parser.read()) {
    setTimeout(function() {
    console.log('---');
    }, 10);
    }
    });

    parser.on('end', function() {
    console.log('parser end');
    });

    parser.on('finish', function() {
    console.log('parser finish');
    });