// 将blob转成data:url
export const readBlob = (blob: Blob): Promise<string> => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader()
    reader.onload = (evt: ProgressEvent<FileReader>) => {
      if (evt.target?.result) {
        resolve(evt.target.result as string)
      }
    }
    reader.onerror = (err: ProgressEvent<FileReader>) => {
      reject(err)
    }
    reader.readAsDataURL(blob)
  })
}

// 下载文件
export const downloadFile = (file: string, fileName: string): void => {
  const a = document.createElement('a')
  a.href = file
  a.download = fileName
  a.click()
}