This issue looks like it's fairly simple: getStringUtf16 builds an array of 16-bit character values in an array and then attempts to create an output string using new Buffer(str). Unfortunately that expects an array of octets and discards the high byte in each of the two-byte values given. This means the method works if every character is actually ASCII, but fails if any UTF-16 pairs are found.
The simple solution I went with was:
// str is an array of two-byte pairs
var buf = new Buffer(str.length*2);
for (var i = 0; i < str.length; i++) {
buf.writeUInt16LE(str[i], i*2);
}
return buf.toString('utf16le');
This issue looks like it's fairly simple: getStringUtf16 builds an array of 16-bit character values in an array and then attempts to create an output string using
new Buffer(str)
. Unfortunately that expects an array of octets and discards the high byte in each of the two-byte values given. This means the method works if every character is actually ASCII, but fails if any UTF-16 pairs are found.The simple solution I went with was:
And that solved my problem.