* 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)
| 3159 | * @return {!Uint8Array} |
| 3160 | */ |
| 3161 | function 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 |
no test coverage detected