Skip to content

Commit 68b2e8a

Browse files
committed
fix: utf16toString(uint16arr) on Big-Endian Node.js
1 parent faf5f1b commit 68b2e8a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

utf16.node.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ function encode(str, loose = false, format = 'uint16') {
3434
throw new Error('Unreachable')
3535
}
3636

37-
const swapped = (x, swap) =>
38-
swap ? Buffer.from(x).swap16() : Buffer.from(x.buffer, x.byteOffset, x.byteLength)
37+
// Convert to Buffer view or a swapped Buffer copy
38+
const swapped = (x, swap) => {
39+
const b = Buffer.from(x.buffer, x.byteOffset, x.byteLength)
40+
return swap ? Buffer.from(b).swap16() : b
41+
}
3942

4043
// We skip TextDecoder on Node.js, as it's is somewhy significantly slower than Buffer for utf16
4144
// Also, it incorrectly misses replacements with Node.js is built without ICU, we fix that

0 commit comments

Comments
 (0)