2021-12-21 00:15:04 +01:00
|
|
|
export class Files {
|
|
|
|
static toString(f: File | Blob): Promise<string> {
|
|
|
|
const reader = new window.FileReader()
|
|
|
|
reader.readAsDataURL(f)
|
|
|
|
return new Promise((resolve) => {
|
|
|
|
reader.onloadend = () => resolve(reader.result as string)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-03-01 02:00:01 +01:00
|
|
|
static async fromString(s: string): Promise<Blob> {
|
2021-12-21 00:15:04 +01:00
|
|
|
return fetch(s).then((r) => r.blob())
|
|
|
|
}
|
|
|
|
}
|