简体   繁体   English

如何解压JavaScript中zlib压缩的object?

[英]How to decompress an object compressed by zlib in JavaScript?

In JavaScript project, I want to decompress an object compressed by zlib( Zopfli.js ) and I'm trying it with pako.min.js .在 JavaScript 项目中,我想解压缩由 zlib( Zopfli.js )压缩的 object ,我正在尝试使用pako.min.js However, the example at the official site of pako uses require function which does not exist in JavaScript.但是, pako 官方网站上使用的示例require function,而 JavaScript 中不存在。 Maybe Node.js has this but I'm afraid it would take a lot of time and pains to combine this JavaScript project with Node.js , because I know nothing about Node.js . Maybe Node.js has this but I'm afraid it would take a lot of time and pains to combine this JavaScript project with Node.js , because I know nothing about Node.js .

Is it any way to get through with this, or another way to decompress the object?有什么办法可以解决这个问题,或者有其他方法可以解压 object?

Any information would be appreciated.任何信息,将不胜感激。

What I've already tried我已经尝试过的

I've already tried zlib.js library for decomressing, but the result is catching the error below which I couldn't find any solution:我已经尝试过zlib.js库进行解压缩,但结果是捕获了下面的错误,我找不到任何解决方案:

const compressed = dataCompressedByZlib;
const inflate = new Zlib.Inflate(compressed);
const plain = inflate.decompress();// -> input buffer is broken

You may use pako.js from here for client side javascript and import it as -您可以从此处将 pako.js 用于客户端 javascript 并将其导入为 -

<script type="text/javascript" src="pako.js"></script>

inside your html, as mentioned here-在您的 html 内部,如此处所述-

https://stackoverflow.com/a/22675078/7895283 https://stackoverflow.com/a/22675078/7895283

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

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