(input, encoding = 'utf8')
| 348 | * @returns {string} |
| 349 | */ |
| 350 | export function uint8ArrayToString(input, encoding = 'utf8') { |
| 351 | assertUint8ArrayOrArrayBuffer(input); |
| 352 | |
| 353 | // Reject anything other than UTF-8 |
| 354 | if (!/utf-?8/i.test(encoding)) { |
| 355 | throw new Error('Encoding "' + encoding + '" isn’t supported without a TextDecoder polyfill'); |
| 356 | } |
| 357 | |
| 358 | // Normalise to Uint8Array |
| 359 | const bytes = input instanceof Uint8Array ? input : new Uint8Array(input); |
| 360 | return decodeUtf8(bytes); |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Minimal UTF-8 decoder |
no test coverage detected