(data: Buffer)
| 82 | } |
| 83 | |
| 84 | function decodeUtf16LeIgnore(data: Buffer): string { |
| 85 | let output = ''; |
| 86 | let i = 0; |
| 87 | |
| 88 | while (i + 1 < data.length) { |
| 89 | const first = data[i]; |
| 90 | const second = data[i + 1]; |
| 91 | if (first === undefined || second === undefined) break; |
| 92 | |
| 93 | const codeUnit = first | (second << 8); |
| 94 | |
| 95 | if (codeUnit >= 0xd800 && codeUnit <= 0xdbff) { |
| 96 | const lowFirst = data[i + 2]; |
| 97 | const lowSecond = data[i + 3]; |
| 98 | if (lowFirst !== undefined && lowSecond !== undefined) { |
| 99 | const low = lowFirst | (lowSecond << 8); |
| 100 | if (low >= 0xdc00 && low <= 0xdfff) { |
| 101 | const codePoint = 0x10000 + ((codeUnit - 0xd800) << 10) + (low - 0xdc00); |
| 102 | output += String.fromCodePoint(codePoint); |
| 103 | i += 4; |
| 104 | continue; |
| 105 | } |
| 106 | } |
| 107 | i += 2; |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | if (codeUnit >= 0xdc00 && codeUnit <= 0xdfff) { |
| 112 | i += 2; |
| 113 | continue; |
| 114 | } |
| 115 | |
| 116 | output += String.fromCodePoint(codeUnit); |
| 117 | i += 2; |
| 118 | } |
| 119 | |
| 120 | return output; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Decode a Buffer into a string with Python-compatible `errors` handling. |
no outgoing calls
no test coverage detected