mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
13 lines
524 B
TypeScript
13 lines
524 B
TypeScript
export function downloadBytesAsFile(bytes: Uint8Array, fileName: string, mimeType: string): void {
|
|
const payload = bytes.slice();
|
|
const blob = new Blob([payload], { type: mimeType || 'application/octet-stream' });
|
|
const objectUrl = URL.createObjectURL(blob);
|
|
const anchor = document.createElement('a');
|
|
anchor.href = objectUrl;
|
|
anchor.download = fileName || 'download.bin';
|
|
document.body.appendChild(anchor);
|
|
anchor.click();
|
|
anchor.remove();
|
|
window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
|
|
}
|