* Interpret a byte array as a UTF-8 string. * @param {!BufferSource} bytes * @return {string}
(bytes)
| 101 | * @return {string} |
| 102 | */ |
| 103 | function utf8Decode(bytes) { |
| 104 | if (typeof TextDecoder !== 'undefined') { |
| 105 | return new TextDecoder('utf-8').decode(bytes); |
| 106 | } |
| 107 | const bytesBuffer = new Uint8Array(bytes.buffer || bytes); |
| 108 | const array = new Array(bytesBuffer.length); |
| 109 | for (let i = 0; i < bytesBuffer.length; i++) { |
| 110 | array[i] = String.fromCharCode(bytesBuffer[i]); |
| 111 | } |
| 112 | const asciiString = array.join(''); |
| 113 | return decodeURIComponent(escape(asciiString)); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Converts a base64 string into a Uint8Array with the corresponding bytes. |
no test coverage detected