简体   繁体   English

如何在 javascript 中解压缩 gzip 文件?

[英]How can I uncompress a gzip file in javascript?

I have gotten an ArrayBuffer data (called s as follows which consist of many blocks) from our serve side,the blob is generated as follows:我从我们的服务端获得了一个ArrayBuffer数据(如下称为 s,由许多块组成),blob 生成如下:

var blob=new Blob([s.slice(4,82838)]);

but the blob I have made is a gzip data;How can I uncompress it in javascript?但是我制作的 blob 是一个 gzip 数据;如何在 javascript 中解压缩它? I have tried zip.js but it didn't work?(and I still puzzled why it doesn't work).我试过zip.js但它没有用?(我仍然不明白为什么它不起作用)。 please tell me a method to un-compress the blob,thank you.请告诉我一种解压缩blob的方法,谢谢。 (my English is poor,sorry) (我的英语很差,对不起)

In the browser I have used pako在浏览器中,我使用了pako

You may do something like..你可以做类似的事情..

var reader = new FileReader();
reader.onload = function(event) {
    var result = pako.inflate(event.target.result, { to: 'string' });
    console.log(result);
}
reader.readAsArrayBuffer(file));

If your environment is nodejs you have zlib capabilities如果您的环境是 nodejs,则您具有zlib 功能

In Nodejs, you can install unzip package.在 Nodejs 中,您可以安装解压包。

npm install unzip

This is the document这是文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM