MCPcopy
hub / github.com/osnr/TabFS / utf8ArrayToBase64

Function utf8ArrayToBase64

extension/background.js:66–82  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

64// btoa cannot be used on Uint8Arrays or strings containing utf8 characters.
65// This is the best solution per https://stackoverflow.com/a/66046176
66const 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
85window.Routes = {};

Callers 1

onMessageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected