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); }