ajax gzip compress a string for postdata

2019-06-07 06:09发布

Can't seem to find anything related to gzip compressing a string. Only find broken sites or suggestions for compressions that won't work as gzip. Also lots of talk of server side implementation. However I wish to send the encoded data from the client.

To give clarification all my clients use greasemonkey or scriptish and all my clients are generally on some version of a recent Firefox or one of it's derivatives, so content encoding for everyone is not an issue.

What I do need is a pure javascript or some sort of library loadable by javascript to gzip compress a string.

1条回答
Bombasti
2楼-- · 2019-06-07 06:31

Just achieved this using https://github.com/dankogai/js-deflate However the postdata for whatever reason will strip the + signs and replace them with spaces.

To send the data via javascript:

params.mapdata= btoa(RawDeflate.deflate(JSON.stringify(mapdata))); 

To receive the data via php:

$value = gzinflate(base64_decode(preg_replace('/\s/', '+',$value))); 
查看更多
登录 后发表回答