JS下载并解压压缩文件
var url = apis.exports; url += "?query=" + query.query;
var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); // 也可以使用POST方式,根据接口 xhr.responseType = "arraybuffer"; // 返回类型arraybuffer xhr.onload = function () { if (this.status === 200) { var data = new Uint8Array(this.response);
// 使用pako插件解压 自行百度下载 var result = pako.inflate(data, { to: 'text/comma-separated-values' }); var blob =new Blob([result]); var reader = new FileReader(); reader.readAsDataURL(blob); reader.onload = function (e) { var a = document.createElement('a'); a.download = 'down.csv'; a.href = e.target.result; $("body").append(a); a.click(); $(a).remove(); } } }; xhr.send(); }