* 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)
| 344 | * @return {!Uint8Array} |
| 345 | */ |
| 346 | function 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 |
no test coverage detected