/**
* 下载压缩包文件
* @param {blob} fileArrayBuffer 文件流
* @param {String} filename 文件名称
* @param {String} fileType 文件格式
*/
export const downloadZip = (fileArrayBuffer, filename, fileType) => {
let data = new Blob([fileArrayBuffer], {
type:
fileType == "zip"
? "application/zip,charset=utf-8"
: "application/x-rar-compressed,charset=utf-8",
});
if (typeof window.chrome !== "undefined") {
// Chrome
var link = document.createElement("a");
link.href = window.URL.createObjectURL(data);
link.download = filename;
link.click();
console.log(data);
} else if (typeof window.navigator.msSaveBlob !== "undefined") {
// IE
var blob = new Blob([data], {
type:
fileType == "zip" ? "application/zip" : "application/x-rar-compressed",
});
window.navigator.msSaveBlob(blob, filename);
} else {
// Firefox
var file = new File([data], filename, {
type:
fileType == "zip" ? "application/zip" : "application/x-rar-compressed",
});
window.open(URL.createObjectURL(file));
}
};
使用示例: