(bytes: Uint8Array)
| 65 | * Create string from UTF-16BE bytes. |
| 66 | */ |
| 67 | export function createStringFromBytes(bytes: Uint8Array): string { |
| 68 | if (bytes.length <= 2) { |
| 69 | // Single character - interpret as UTF-16BE code point |
| 70 | let code = 0; |
| 71 | |
| 72 | for (let i = 0; i < bytes.length; i++) { |
| 73 | code = (code << 8) | bytes[i]; |
| 74 | } |
| 75 | |
| 76 | return String.fromCharCode(code); |
| 77 | } |
| 78 | |
| 79 | // Multi-byte: interpret as UTF-16BE string |
| 80 | let result = ""; |
| 81 | |
| 82 | for (let i = 0; i + 1 < bytes.length; i += 2) { |
| 83 | result += String.fromCharCode((bytes[i] << 8) | bytes[i + 1]); |
| 84 | } |
| 85 | |
| 86 | return result; |
| 87 | } |
no outgoing calls
no test coverage detected