blob: 6d6ed0365db0f5f6525c95c4f7b53bcbcd7b3a81 [file] [log] [blame]
Adrià Vilanova Martínez7f1e8ea2022-10-14 15:50:11 +02001// Source: https://stackoverflow.com/a/66046176
2export const arrayBufferToBase64 = async (data) => {
3 // Use a FileReader to generate a base64 data URI
4 const base64url = await new Promise((r) => {
5 const reader = new FileReader();
6 reader.onload = () => r(reader.result);
7 reader.readAsDataURL(new Blob([data]));
8 });
9
10 /*
11 The result looks like
12 "data:application/octet-stream;base64,<your base64 data>",
13 so we split off the beginning:
14 */
15 return base64url.split(',', 2)[1]
16}