Javascript string compression and unpacking PHP / Ruby

Is there any Javascript compression and PHP / Ruby unpacking library for strings? I need this because I need to send a very long text string using Ajax on a slow link to load to a web server that uses PHP / Ruby as the server language.

var x = $('#sources').html(); // a very-very long text var xo = x, o = {}; if(x.length>512*1024) { x = compress(x); oc = 1; } ox = x; $.post('target.php',o,function(res){alert(res==xo)}); 

On the server side (e.g. PHP):

 <?php if(isset($_POST['c']) && $_POST['c']=='1') { $x = decompress($_POST['x']); } else { $x = $_POST['x']; } echo $x; 
+6
source share
4 answers

There are many JS implementations of the most common compression algorithm, Zip.

For example zip.js

Zip, of course, is supported in PHP .

+4
source

It should do it

http://webdevwonders.com/lzw-compression-and-decompression-with-javascript-and-php/

LZW is good for lines that really contain human readable text.

+2
source

Assuming you send your files via http, I suggest that you allow the web server to handle this by sending a file encoded with gzip content.

If, for example, you use Apache, you can enable mod_deflate

If for some reason you cannot change the configuration of your web server, php also has a built-in gzip handler that you could use instead. See: ob_gzhandler

Edit:

As a client to server, it looks like this is directly supported by any implementation of XmlHttpRequest. Perhaps you can find your own gzip compression algorithm for Javascript, and then set the request header to indicate that it is compressed. Thus, it becomes a transparently decoded web server, and you do not need to do anything special in php.

See this page: JavaScript implementation of Gzip .

0
source

Running a google search for a ruby ​​debpress string results in the following: How to unzip a Gzip string in ruby? which you are looking for.

0
source

All Articles