ashtuchkin / iconv-lite

Convert character encodings in pure javascript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UTF-16BE not exported correctly

suckerp opened this issue · comments

HI,

I'm trying to export a JSON to later import into SQL Server. For that I need to use a UTF-16BE encoded file.

My problem is that when I try to convert it to UTF-16BE (utf16be) I get ANSI encoded file with only NUL entries. When I convert it into utf16 (le) it works correctly.
Here's what I'm doing.

//to write the data from the arry into a UTF-8 File I use the standard writeFile function.
fs.writeFile(filename, JSON.stringify(data, null, 4), 'utf8')

//Input opens the previously written UTF-8 encoded file and the it should be converted into UTF-16BE but here's where I run into problems
fs.createReadStream(input)
.pipe(iconv.decodeStream('utf8'))
.pipe(iconv.encodeStream('utf16be'))
.pipe(fs.createWriteStream(output))

grafik

Like I said before when I use something like utf16 or utf16le instead of utf16be I get the correct output file for that encoding. But not for utf16be.

Is anybody else having the same issue with the UTF-16BE encoding?