I need to copy one large data file to another destination with some modifications. fs.readFile
and fs.writeFile
are very slow. I need to read line by line, modify and write to new file. I found something like this:
fs.stat(sourceFile, function(err, stat){
var filesize = stat.size;
var readStream = fs.createReadStream(sourceFile);
// HERE I want do some modifications with bytes
readStream.pipe(fs.createWriteStream(destFile));
})
But how to make modifications ? I tried to get data with data
event
readStream.on('data', function(buffer){
var str = strToBytes(buffer);
str.replace('hello', '');
// How to write ???
});
but don't understand how to write it to file: