Client side data compress/decompress? [closed]

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

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"}); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!