MCPcopy Create free account
hub / github.com/editablejs/editable / readBase64WithFetch

Function readBase64WithFetch

packages/plugins/image/src/utils.ts:19–36  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

17}
18
19const readBase64WithFetch = (url: string) => {
20 return new Promise<string>((resolve, reject) => {
21 const xhr = new XMLHttpRequest()
22 xhr.onload = () => {
23 const reader = new FileReader()
24 reader.onloadend = () => {
25 resolve(reader.result as string)
26 }
27 reader.onerror = error => {
28 reject(error)
29 }
30 reader.readAsDataURL(xhr.response)
31 }
32 xhr.open('GET', url)
33 xhr.responseType = 'blob'
34 xhr.send()
35 })
36}
37
38export const readBase64 = (file: File | string) => {
39 return typeof file === 'string' ? readBase64WithFetch(file) : readBase64WithFileReader(file)

Callers 1

readBase64Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…