Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
streams fun
var findit = require('findit')('./posts');
findit.on('file', function(file, stat) {
(fs.createReadStream(file)).pipe(through(function(data) {
this.queue(marked(data.toString()));
})).pipe(process.stdout);
});
@mulderp

This comment has been minimized.

Copy link
Owner Author

commented Nov 11, 2014

attempt to pipe contents onto index html

var rs = fs.createReadStream('./templates/index.html');
var tr = trumpet();
rs.pipe(tr);
var findit = require('findit')('./posts');
findit.on('file', function(file, stat) {
  (fs.createReadStream(file)).pipe(through(function(data) {
    this.queue(marked(data.toString()));
  })).pipe(tr.select('body').createStream()).pipe(process.stdout);
});
@mulderp

This comment has been minimized.

Copy link
Owner Author

commented Nov 11, 2014

hmm.. still not the wanted output...

var duplexer = require('duplexer');
var rs = fs.createReadStream('./templates/index.html');
var tr = trumpet();

var indexStream = (function() {

  var input = concat(function(data) {
    output.queue(data.toString());
    output.queue(null);
  });
  var output = through();

  return duplexer(input, output);

})();

var findit = require('findit')('./posts');
findit.on('file', function(file, stat) {
  (fs.createReadStream(file)).pipe(through(function(data) {
    this.queue(marked(data.toString()));
  })).pipe(indexStream);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.