admin管理员组文章数量:1415673
Is there a Javascript pression and PHP/Ruby depression 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 = press(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 = depress($_POST['x']);
} else {
$x = $_POST['x'];
}
echo $x;
Is there a Javascript pression and PHP/Ruby depression 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 = press(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 = depress($_POST['x']);
} else {
$x = $_POST['x'];
}
echo $x;
Share
Improve this question
edited Feb 14, 2013 at 8:31
Kokizzu
asked Feb 14, 2013 at 8:04
KokizzuKokizzu
26.9k40 gold badges149 silver badges256 bronze badges
4 Answers
Reset to default 4There are many JS implementations of the most mon pression algorithm, Zip.
For example zip.js
Zip is of course also supported in PHP.
That should do it
http://webdevwonders./lzw-pression-and-depression-with-javascript-and-php/
LZW is good for strings that actually contain human readable text
Assuming that you send your files over http, I would suggest that you let your web server handle this by sending file with gzip content-encoding.
If for example you use Apache, you can enable mod_deflate
If for some reason you can't change your web server configuration, php also has a built-in gzip handler you could use instead. See: ob_gzhandler
Edit:
As for client to server, it doesn't look like this is directly supported by any XmlHttpRequest implementations. You could perhaps find a custom gzip pression algorithm for Javascript and then set the request-header to indicate that it's pressed .That way it bees transparently decoded by the web server and you don't have to do anything special in php.
See this page: JavaScript implementation of Gzip.
Running a google search for "ruby depress string" es up with this: How to depress Gzip string in ruby? which is what you're looking for.
本文标签: Javascript string compression and PHPRuby decompressionStack Overflow
版权声明:本文标题:Javascript string compression and PHPRuby decompression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745211376a2647905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论