Line data Source code
1 : import { FileDownloader } from './file_downloader.js';
2 :
3 1 : export class WebFileDownloader implements FileDownloader {
4 1 : async downloadBufferAsFile(uint8Array: Uint8Array, filename: string): Promise<void> {
5 : // Create a Blob from the Uint8Array
6 1 : const blob = new Blob([uint8Array as BlobPart], { type: 'application/octet-stream' });
7 : // Create a temporary URL for the Blob
8 1 : const url = URL.createObjectURL(blob);
9 : // Create an anchor element and trigger the download
10 1 : const a = document.createElement('a');
11 1 : a.href = url;
12 1 : a.download = filename;
13 1 : document.body.appendChild(a);
14 1 : a.click();
15 : // Clean up after download
16 1 : document.body.removeChild(a);
17 : // Release blob memory
18 1 : URL.revokeObjectURL(url);
19 1 : }
20 1 : }
|