function utf16leSlice (buf, start, end) {
var bytes = buf.slice(start, end)
var res = ''
- for (var i = 0; i < bytes.length; i += 2) {
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
+ for (var i = 0; i < bytes.length - 1; i += 2) {
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
}
return res
t.end()
})
+test('utf16le to utf16 with odd byte length input', function (t) {
+ t.equal(
+ new B(new B('abcde', 'utf8').toString('utf16le'), 'utf16le').toString('utf8'),
+ 'abcd'
+ )
+ t.end()
+})
+
test('utf16le to hex', function (t) {
t.equal(
new B('abcd', 'utf16le').toString('hex'),