问题
I'm looking for a JavaScript implementation of a string compress/decompress algorithm where data is created at the client side and stored in hidden fields within HTML forms.
I read about gzip, but it compresses the data server side whereas in my case I want to compress it client side, send it to the server, or receive it from server to decompress it again at client side.
I found this LZF Compression example based on LZFjs but it will generate binary data which needs to be processed and stored in a hidden form field, and it works on files rather than pure data.
Suggestions on a pure data client-side data compression/decompression that is also efficient?
回答1:
There is this open-source Javascript compression library, by Pierre curto : https://github.com/pierrec/node-lz4
Googling around, I also found this zlib implementation (not tested by me) : http://nodejs.org/api/zlib.html
回答2:
You may also try JSZip. To run it in browser you just have to download and include dist/jszip.js or dist/jszip.min.js.
This is actively supported and supports a wide variety of browsers including everyone's favorite IE6/7/8!
Usage (from their docs):
var zip = new JSZip(); zip.file("Hello.txt", "Hello World\n"); var img = zip.folder("images"); img.file("smile.gif", imgData, {base64: true}); var content = zip.generate({type:"blob"});
来源:https://stackoverflow.com/questions/16275512/client-side-data-compress-decompress