| 64 | // btoa cannot be used on Uint8Arrays or strings containing utf8 characters. |
| 65 | // This is the best solution per https://stackoverflow.com/a/66046176 |
| 66 | const utf8ArrayToBase64 = async (data) => { |
| 67 | if(data.length == 0) return ''; |
| 68 | |
| 69 | // Use a FileReader to generate a base64 data URI |
| 70 | const base64url = await new Promise((r) => { |
| 71 | const reader = new FileReader() |
| 72 | reader.onload = () => r(reader.result) |
| 73 | reader.readAsDataURL(new Blob([data])) |
| 74 | }); |
| 75 | |
| 76 | /* |
| 77 | The result looks like |
| 78 | "data:application/octet-stream;base64,<your base64 data>", |
| 79 | so we split off the beginning: |
| 80 | */ |
| 81 | return base64url.split(",", 2)[1] |
| 82 | }; |
| 83 | |
| 84 | // global so it can be hot-reloaded |
| 85 | window.Routes = {}; |