Created
January 24, 2011 15:26
-
-
Save dogeared/793373 to your computer and use it in GitHub Desktop.
Node Read/Write Streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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