summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/export.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/lib/export.ts')
-rw-r--r--apps/web/src/lib/export.ts20
1 files changed, 20 insertions, 0 deletions
diff --git a/apps/web/src/lib/export.ts b/apps/web/src/lib/export.ts
index 67621e16..ae68144b 100644
--- a/apps/web/src/lib/export.ts
+++ b/apps/web/src/lib/export.ts
@@ -16,3 +16,23 @@ export function getExportFileExtension({
}): string {
return `.${format}`;
}
+
+export function downloadBuffer({
+ buffer,
+ filename,
+ mimeType,
+}: {
+ buffer: ArrayBuffer;
+ filename: string;
+ mimeType: string;
+}): void {
+ const blob = new Blob([buffer], { type: mimeType });
+ const url = URL.createObjectURL(blob);
+ const downloadLink = document.createElement("a");
+ downloadLink.href = url;
+ downloadLink.download = filename;
+ document.body.appendChild(downloadLink);
+ downloadLink.click();
+ document.body.removeChild(downloadLink);
+ URL.revokeObjectURL(url);
+}