MCPcopy Index your code
hub / github.com/ampproject/amphtml / stringToBytes

Function stringToBytes

third_party/subscriptions-project/swg.js:3161–3169  ·  view source on GitHub ↗

* Converts a string which holds 8-bit code points, such as the result of atob, * into a Uint8Array with the corresponding bytes. * If you have a string of characters, you probably want to be using utf8Encode. * @param {string} str * @return {!Uint8Array}

(str)

Source from the content-addressed store, hash-verified

3159 * @return {!Uint8Array}
3160 */
3161function stringToBytes(str) {
3162 const bytes = new Uint8Array(str.length);
3163 for (let i = 0; i < str.length; i++) {
3164 const charCode = str.charCodeAt(i);
3165 assert(charCode <= 255, 'Characters must be in range [0,255]');
3166 bytes[i] = charCode;
3167 }
3168 return bytes;
3169}
3170
3171/**
3172 * Converts a 8-bit bytes array into a string

Callers 3

utf8EncodeSyncFunction · 0.70
base64UrlDecodeToBytesFunction · 0.70
createPair_Method · 0.70

Calls 1

assertFunction · 0.70

Tested by

no test coverage detected