Skip to content

Instantly share code, notes, and snippets.

@dogeared
Created January 24, 2011 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogeared/793373 to your computer and use it in GitHub Desktop.
Save dogeared/793373 to your computer and use it in GitHub Desktop.
Node Read/Write Streams
sanitizeFile: function(reportFile, columnAdditions, rowDeletions, callback, retryCount) {
var rs = fs.createReadStream(reportFile, { encoding:'utf8' })
, outputFile = path.dirname(reportFile) + "/" + path.basename(reportFile) + ".sanitized"
, ws = fs.createWriteStream(outputFile);
rs.on('data', function(data) {
var flushed = ws.write(data);
if (!flushed) { rs.pause(); }
});
rs.on('end', function() {
callback(reportFile);
});
ws.on('drain', function() {
rs.resume();
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment