}
function utf16leWrite (buf, string, offset, length) {
- var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length, 2)
+ var charsWritten = blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length, 2)
return charsWritten
}
return byteArray
}
-function utf16leToBytes (str) {
+function utf16leToBytes (str, units) {
var c, hi, lo
var byteArray = []
for (var i = 0; i < str.length; i++) {
+
+ if ((units -= 2) < 0) break
+
c = str.charCodeAt(i)
hi = c >> 8
lo = c % 256