0

I'm trying to compress a massive JS object on the client side via Pako and than get it back on the PHP-script.

JS code

const save_str = JSON.stringify(massive_object);
const gz_str = pako.gzip(save_str, { to: 'string' });
$.post('/', 
       {data:window.btoa(unescape(encodeURIComponent(gz_str)))}, 
       (data)=>{ console.log(data); },
       'json');

PHP code

$res = gzinflate(base64_decode($_POST['data']));

Should be quite straight-forward thing but I keep getting gzinflate(): data error. Already spent a few hours dancing around, still no result. Begging for help!

Denis O.
  • 1,841
  • 19
  • 37

1 Answers1

1

You want gzdecode(), not gzinflate().

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • @mark thanks a lot, it helped! Another problem I had was obsolete `unescape` and `encodeURIComponent` usage, base64 encoding seems to be enough, but the main issue was wrong decompressing function used. Have to pay more attention to the theory. – Denis O. Oct 24 '18 at 07:47
  • For some reason that is not working for me. I've tried `gzdecode(base64_decode($stringToInflate));` and `gzdecode($stringToInflate);` – Chewie The Chorkie Mar 03 '21 at 03:34