1

Is there a compression library that has both PHP and JavaScript implementation, such that I can compress/decompress from/to JavaScript/PHP interchangeably? I know there are different options to compress data with PHP or JavaScript, the problem is that they store their output with different metadata. This means for example, that if some data is compressed into file output.bin using PHP, once I read output.bin using JavaScript (ajax) there is no way I can decompress that stream.

PS: I'm not looking for compression of HTTP requests, I have a bunch of compressed files (throught PHP) which I need to retrieve and decompress using JavaScript.

Thanks

3
  • What compression format? Commented Jan 10, 2013 at 0:12
  • Why not let the server do it? Compression algorithms generally aren't the best left to handle by the browser because they can be expensive on the CPU. Commented Jan 10, 2013 at 0:13
  • You are right Austin, but I cannot set up any server-side script. My requirements are that I can only retrieve some binary (compressed) file. I cannot hack with HTTP headers, gzlib, URLs and the like. Anyway, DEFLATE would be a good tradeoff. Commented Jan 10, 2013 at 0:41

3 Answers 3

1

I don't know if something like node.js would fit into your scheme, but it provides fast zlib compression and decompression. php has zlib as well, so that would meet your requirements. If you need a zlib clone written entirely in Javascript, there are several out there that show up in a google search. However I don't know if any are complete or correct.

Sign up to request clarification or add additional context in comments.

Comments

0

It's going to be trickier on the Javascript side than the PHP side, but there's lots of discussion and links here.

Comments

0

I'd suggest looking into HTTP-level compression. But if you really want to do this by hand, you could use zlib for example. Both PHP and JS have implementations:

http://www.php.net/manual/en/ref.zlib.php

https://github.com/imaya/zlib.js

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.