I've been trying to make a simple copy/paste program in Node JS but can't do it because of a problem. I am able to copy the contents of source file as Buffer and write it to another file but while writing, node js messes with newlines and therefore destination file is not as same as source file. The code I use:
var fs = require('fs')
var lazy = require('lazy')
var readStream = fs.createReadStream("SOURCE_FILE.EXE")
var writeStream = fs.createWriteStream("DESTINATION_FILE.EXE", 'binary', { flags : 'w' })
var write = function(line) {
writeStream.write(line)
}
new lazy(readStream)
.lines
.forEach(function(line) {
console.log(line) // Buffer of each line of file
write(line)
})
I use writing buffer of each line one by one so that it doesn't hang on big files. All data is same in SOURCE_FILE and DESTINATION_FILE except some newlines.
Help is really appreciated. Thanks in advance.