Skip to content
Advertisement

The gzuncompress of php equivalent on javascript

I have a php file that do:

echo(gzcompress("TEST COMPRESS"));

and on javascript i do a request on php and i want a function that do the same of gzuncompress(data) for take the result = “TEST COMPRESS” again on client side.

EDIT: Thank you @aaronk6, zlib worked!

If someone ready this question, the zlib will works if the php is with gzencode(), gzcompress will not work.

Advertisement

Answer

As @SLaks pointed out, this is might be pointless, however here’s an answer to your question.

Browsers do not have a uncompress method that is accessible from JavaScript, so there’s no equivalent. When you want to decompress gzipped data in JavaScript, you will need to use a JavaScript implementation of the gzip algorithm.

There’s zlib.js which seems to be capable of doing this.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement