Skip to content

Instantly share code, notes, and snippets.

@soldair
Created September 8, 2012 21:37
Show Gist options
  • Save soldair/3679955 to your computer and use it in GitHub Desktop.
Save soldair/3679955 to your computer and use it in GitHub Desktop.
pause node walkdir, read a file into a write stream, then resume
// walkdir ~0.0.5
var fs = require('fs')
, walkdir = require('../walkdir')
// write all logs to the logs.cat file
, ws = fs.createWriteStream('logs.cat')
;
var em = walkdir('./');
em.on('file',function(path,stat){
if(path.indexOf('.log') != path.length-4) return;
em.pause();
var rs = fs.createReadStream(path);
rs.on('end',function(){
em.resume();
});
rs.on('data',function(buf){
ws.write(buf);
});
});
em.on('end',function(){
console.log('done!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment