From: Jesse Tane Date: Sun, 7 Dec 2014 18:27:21 +0000 (-0500) Subject: only blit whole code units X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=dff29085b184e9c137514b7cc2da422164e89765;p=buffer.git only blit whole code units --- diff --git a/index.js b/index.js index 03bce7a..0cc3546 100644 --- a/index.js +++ b/index.js @@ -349,7 +349,7 @@ function base64Write (buf, string, offset, length) { } function utf16leWrite (buf, string, offset, length) { - var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length) + var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length, 2) return charsWritten } @@ -1033,7 +1033,8 @@ function base64ToBytes (str) { return base64.toByteArray(str) } -function blitBuffer (src, dst, offset, length) { +function blitBuffer (src, dst, offset, length, unitSize) { + if (unitSize) length -= length % unitSize; for (var i = 0; i < length; i++) { if ((i + offset >= dst.length) || (i >= src.length)) break