如何解压缩javascript中的gzip文件? [英] How can I uncompress a gzip file in javascript?

查看:109
本文介绍了如何解压缩javascript中的gzip文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务端获得了一个 ArrayBuffer 数据(以下称为s,由许多块组成),该blob的生成方式如下:

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:

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

但是我创建的Blob是gzip数据;如何在javascript中解压缩?我已经尝试过 zip.js ,但是它没有用?(并且我仍然感到困惑,为什么它不起作用).请告诉我一种解压缩Blob的方法,谢谢.(我的英语不好,很抱歉)

but the blob I have made is a gzip data;How can I uncompress it in javascript? I have tried zip.js but it didn't work?(and I still puzzled why it doesn't work). please tell me a method to un-compress the blob,thank you. (my English is poor,sorry)

推荐答案

在浏览器中,我使用了 pako

In the browser I have used 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));

如果您的环境是nodejs,则具有 zlib功能

If your environment is nodejs you have zlib capabilities

这篇关于如何解压缩javascript中的gzip文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆