about summary refs log tree commit diff
path: root/src/lib/media/manip.web.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/media/manip.web.ts')
-rw-r--r--src/lib/media/manip.web.ts25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/lib/media/manip.web.ts b/src/lib/media/manip.web.ts
index 522aa2e51..25315ebbd 100644
--- a/src/lib/media/manip.web.ts
+++ b/src/lib/media/manip.web.ts
@@ -1,6 +1,7 @@
-import {Dimensions} from './types'
 import {Image as RNImage} from 'react-native-image-crop-picker'
-import {getDataUriSize, blobToDataUri} from './util'
+
+import {Dimensions} from './types'
+import {blobToDataUri, getDataUriSize} from './util'
 
 export async function compressIfNeeded(
   img: RNImage,
@@ -138,3 +139,23 @@ function createResizedImage(
     img.src = dataUri
   })
 }
+
+export async function saveBytesToDisk(
+  filename: string,
+  bytes: Uint8Array,
+  type: string,
+) {
+  const blob = new Blob([bytes], {type})
+  const url = URL.createObjectURL(blob)
+  await downloadUrl(url, filename)
+  // Firefox requires a small delay
+  setTimeout(() => URL.revokeObjectURL(url), 100)
+  return true
+}
+
+async function downloadUrl(href: string, filename: string) {
+  const a = document.createElement('a')
+  a.href = href
+  a.download = filename
+  a.click()
+}