UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

23 lines (22 loc) 947 B
// SPDX-License-Identifier: Apache-2.0 import { isSafari } from '../utils/utils.js'; import { saveAs } from 'file-saver'; /** * A function to start a download for a file. * * @param content The content of the file to download. * @param fileName The name of the file to download. * @param opt_fileType The type of the file to download. */ export const download = (content, fileName, opt_fileType) => { // Safari does not properly work with FileSaver. Using the the type 'text/plain' // makes it a least possible to show the file content so that users can // do a manual download with "Save as". // See also: https://github.com/eligrey/FileSaver.js/issues/12 const fileType = opt_fileType !== undefined && !isSafari() ? opt_fileType : 'text/plain;charset=utf-8'; const blob = new Blob([ new Uint8Array([0xef, 0xbb, 0xbf]), // UTF-8 BOM content ], { type: fileType }); saveAs(blob, fileName); };