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

Function stringToBytes

third_party/subscriptions-project/swg-gaa.js:346–354  ·  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

344 * @return {!Uint8Array}
345 */
346function stringToBytes(str) {
347 const bytes = new Uint8Array(str.length);
348 for (let i = 0; i < str.length; i++) {
349 const charCode = str.charCodeAt(i);
350 assert(charCode <= 255, 'Characters must be in range [0,255]');
351 bytes[i] = charCode;
352 }
353 return bytes;
354}
355
356/**
357 * Converts a 8-bit bytes array into a string

Callers 1

base64UrlDecodeToBytesFunction · 0.70

Calls 1

assertFunction · 0.70

Tested by

no test coverage detected