export function downloadBlobFile(blob: Blob, fileName: string) {
  if (blob.size === 0) {
    throw new Error('Empty file')
  }

  const objectUrl = URL.createObjectURL(blob)
  const anchor = document.createElement('a')
  anchor.href = objectUrl
  anchor.download = fileName
  anchor.click()
  URL.revokeObjectURL(objectUrl)
}

export function downloadJsonFile<T>(data: T, fileName: string) {
  const blob = new Blob([JSON.stringify(data, null, 2)], {
    type: 'application/json',
  })
  downloadBlobFile(blob, fileName)
}
