forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1export function extractDataUriMime(uri: string): string {
2 return uri.substring(uri.indexOf(':') + 1, uri.indexOf(';'))
3}
4
5// Fairly accurate estimate that is more performant
6// than decoding and checking length of URI
7export function getDataUriSize(uri: string): number {
8 return Math.round((uri.length * 3) / 4)
9}
10
11export function isUriImage(uri: string): boolean {
12 return /\.(jpg|jpeg|png|webp).*$/.test(uri)
13}
14
15export function blobToDataUri(blob: Blob): Promise<string> {
16 return new Promise((resolve, reject) => {
17 const reader = new FileReader()
18 reader.onloadend = () => {
19 if (typeof reader.result === 'string') {
20 resolve(reader.result)
21 } else {
22 reject(new Error('Failed to read blob'))
23 }
24 }
25 reader.onerror = reject
26 reader.readAsDataURL(blob)
27 })
28}