(blob: Blob, filename: string)
| 10 | } |
| 11 | |
| 12 | export function downloadBlob(blob: Blob, filename: string): void { |
| 13 | const url = URL.createObjectURL(blob); |
| 14 | const now = Date.now(); |
| 15 | const fireAt = Math.max(now, nextDownloadSlotAt); |
| 16 | nextDownloadSlotAt = fireAt + DOWNLOAD_STAGGER_MS; |
| 17 | |
| 18 | const trigger = () => { |
| 19 | const a = document.createElement('a'); |
| 20 | a.href = url; |
| 21 | a.download = filename; |
| 22 | document.body.appendChild(a); |
| 23 | a.click(); |
| 24 | document.body.removeChild(a); |
| 25 | setTimeout(() => URL.revokeObjectURL(url), DOWNLOAD_REVOKE_DELAY_MS); |
| 26 | }; |
| 27 | |
| 28 | if (fireAt === now) trigger(); |
| 29 | else setTimeout(trigger, fireAt - now); |
| 30 | } |
| 31 | |
| 32 | export function downloadFile(data: ArrayBuffer | string, filename: string): void { |
| 33 | const blob = |
no test coverage detected