javascript - 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.
However, the example at the official site of pako uses require
function which does not exist in 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
.
Is it any way to get through with this, or another way to decompress the 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:
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 -
<script type="text/javascript" src="pako.js"></script>
inside your html, as mentioned here-
推荐阅读
- mongodb - 为了避免依赖关系,是否值得创建一个相同的映射类?
- c++ - MIL vs. fieldname vs. this->fieldname
- python - 需要帮助,创建的代码和累加器不计算文本文件中的大写字母
- javascript - 使用不带 jQuery 的 JavaScript 从多个不同的选定下拉列表项中获取值
- prestashop - 如何在 Prestashop 1.6 中创建对象购物车
- javascript - Attach Div to Th id / django forloop counter issue
- c# - 如何在 Unity 新的 2D 光照系统中创建 Tilemap 光照?
- php - laravel 查看更多分类
- swift - 如何在 Xcode 中授予 Accessibilty 访问权限
- android - 用于安卓的离子构建