Skip to content

Function: triggerDownload() ​

ts
function triggerDownload(
   data, 
   fileName, 
   mimeType?
): void;

Defined in: browser.ts:36

Prompts the browser to save data under fileName.

Creates a temporary object URL and clicks a hidden anchor, then cleans both up. The URL is revoked on the next tick rather than immediately, because revoking synchronously cancels the download in some browsers.

Parameters ​

ParameterTypeDefault valueDescription
dataUint8Array<ArrayBufferLike> | BlobundefinedThe bytes to save. A Uint8Array is copied into a fresh buffer first, since a view into WebAssembly memory may cover more than it appears to and Blob would capture the whole thing.
fileNamestringundefinedName offered in the save dialog, extension included.
mimeTypestring'application/zip'Content type for the blob. Defaults to application/zip.

Returns ​

void

Throws ​

Outside a browser — in Node, write the bytes with fs.writeFile instead.

Example ​

ts
const zip = await writeShapefileZip(data, { fileName: 'parcels' });
triggerDownload(zip, 'parcels.zip');

Released under the MIT License.