blob: ae68144bc3bb0160175e052e7272861a44987f95 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import { EXPORT_MIME_TYPES } from "@/constants/export-constants";
import type { ExportFormat } from "@/types/export";
export function getExportMimeType({
format,
}: {
format: ExportFormat;
}): string {
return EXPORT_MIME_TYPES[format];
}
export function getExportFileExtension({
format,
}: {
format: ExportFormat;
}): 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);
}
|