[英]Decompress a GZIP CSV file on client side with Pako.js
I want to load a large gzipped CSV file using the Fetch API and Pako.js with client-side code.我想使用 Fetch API 和带有客户端代码的 Pako.js 加载一个大的 gzip 压缩文件 CSV。 This is the code I was using:这是我使用的代码:
const res = await fetch('www.example.com/large.csv.gzip');
let raw = await res.text();
raw = pako.inflate(raw);
console.log(raw);
I got an error without any stack trace:我收到一个没有任何堆栈跟踪的错误:
Uncaught (in promise) unknown compression method
I found some examples, but they didn't relate to CSV files, the Fetch API, or both:我找到了一些示例,但它们与 CSV 文件、Fetch API 或两者无关:
Firefox 108.0.2 (64-bit) Firefox 108.0.2(64 位)
Pako.js version 2.1.0 Pako.js 版本 2.1.0
I came across a Codepen that was using XHR requests and setting the response type to an array buffer.我遇到了一个使用 XHR 请求并将响应类型设置为数组缓冲区的Codepen 。
So I tried that with the Fetch API and the code worked!所以我用 Fetch API 试了一下,代码成功了!
const res = await fetch('www.example.com/large.csv.gzip');
let raw = await res.arrayBuffer();
raw = pako.inflate(raw);
console.log(raw); // Prints CSV file content successfully
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.