I've been trying to convert from utf8 string to windows-1255 string for along time now. I came up with this code:
var fs = require('fs');
var Iconv = require('iconv').Iconv;
var iconvlite = require('iconv-lite');
var windows1255 = require('windows-1255');
/////////////////// Attempting to converted from utf-8 to windows-1255
function encode(content) {
var iconv = new Iconv('UTF-8', 'CP1255//TRANSLIT//IGNORE');
var buffer2 = iconv.convert(content);
return buffer2;
//return buffer.toString('ISO-88591-1'); // toString cannot convert in the encoding windows1255
};
var buffer3 = new Buffer(encode(fs.readFileSync('/home/USER/git/npm-test-1/utf8.txt')));
console.log(buffer3);
//str = iconvlite.decode(buffer3, 'win1255');
str = iconvlite.decode(buffer3, "1255");
console.log(str);
fs.writeFile("/home/USER/git/npm-test-1/windows-1255.txt", str, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
Only problem is on the last step, when I'm trying to convert from a buffer to a string. It converts it alright but to a utf8 encoding string :|
Is this a bug?
Is there any way around this? I really need windows-1255 string and not a buffer.
- Anyone knows a way to do this?