MCPcopy
hub / github.com/marimo-team/marimo / blobToString

Function blobToString

frontend/src/utils/fileToBase64.ts:14–34  ·  view source on GitHub ↗
(
  input: Blob | File,
  format: "base64" | "dataUrl",
)

Source from the content-addressed store, hash-verified

12 * @returns A promise that resolves to the requested string representation.
13 */
14export function blobToString(
15 input: Blob | File,
16 format: "base64" | "dataUrl",
17): Promise<string> {
18 return new Promise((resolve) => {
19 const reader = new FileReader();
20 reader.readAsDataURL(input);
21 reader.onload = (e) => {
22 if (e.target?.result) {
23 const dataURL = e.target.result as string;
24 if (format === "base64") {
25 // Extract base64 content from data URL. data:*/*;base64,contents
26 const base64Content = dataURL.slice(dataURL.indexOf(",") + 1);
27 resolve(base64Content);
28 } else {
29 resolve(dataURL);
30 }
31 }
32 };
33 });
34}
35
36/**
37 * Read contents of files as base64-encoded strings

Callers 5

convertToFileUIPartFunction · 0.90
blob.test.tsFile · 0.90
MicrophoneFunction · 0.90
filesToBase64Function · 0.85

Calls 3

sliceMethod · 0.80
indexOfMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…