Javascript string compression and PHPRuby decompression - Stack Overflow

Is there a Javascript pression and PHPRuby depression library for strings? I need it because I need to

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
Add a ment  | 

4 Answers 4

Reset to default 4

There 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211376a4616859.html

相关推荐

  • Javascript string compression and PHPRuby decompression - Stack Overflow

    Is there a Javascript pression and PHPRuby depression library for strings? I need it because I need to

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信