I have file encoded with koi8-u
I need to just copy this file, but, through toString()
fs = require('fs')
fs.readFile('fileOne',function(e,data){
data = data.toString() // now encoding is damaged
??? // my code must be here
fs.writeFile('fileTwo',data)
})
I tried iconv it back using different charsets but with no success. Thanks!
You need to write and read everything with binary encoding:
There should be two way to do this.
Read data as Buffer:
fs = require('fs')
fs.readFile('fileOne', function(e, data){
// data is a buffer
string = data.toString('binary')
fs.writeFile('fileTwo', {
'encoding': 'binary'
}, string);
});
Read data as binary encoded string:
fs = require('fs')
fs.readFile('fileOne', {
'encoding': 'binary'
}, function(e, data){
// data is a string
fs.writeFile('fileTwo', {
'encoding': 'binary'
}, data);
});