How to decompress an object compressed by zlib in JavaScript?

1.8k views Asked by At

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
1

There are 1 answers

0
Pawan Sharma On BEST ANSWER

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-

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