Is there a Javascript compression and PHP/Ruby decompression library for strings? I need it because I need to send a very long text string using Ajax on a slow upload link to a web server which uses PHP/Ruby as server-side language.
var x = $('#sources').html();
// a very-very long text
var xo = x, o = {};
if(x.length>512*1024) {
x = compress(x);
o.c = 1;
}
o.x = x;
$.post('target.php',o,function(res){alert(res==xo)});
On server side (for example, PHP):
<?php
if(isset($_POST['c']) && $_POST['c']=='1') {
$x = decompress($_POST['x']);
} else {
$x = $_POST['x'];
}
echo $x;
There are many JS implementations of the most common compression algorithm, Zip.
For example zip.js
Zip is of course also supported in PHP.
That should do it
http://webdevwonders.com/lzw-compression-and-decompression-with-javascript-and-php/
LZW is good for strings that actually contain human readable text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With