MCPcopy Create free account
hub / github.com/ampproject/amphtml / utf8Decode

Function utf8Decode

third_party/subscriptions-project/aes_gcm.js:103–114  ·  view source on GitHub ↗

* Interpret a byte array as a UTF-8 string. * @param {!BufferSource} bytes * @return {string}

(bytes)

Source from the content-addressed store, hash-verified

101 * @return {string}
102 */
103function 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.

Callers 1

decryptAesGcmImplFunction · 0.70

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected