Really simple short string compression

2019-01-09 05:46发布

Is there a really simple compression technique for strings up to about 255 characters in length (yes, I'm compressing URLs)?

I am not concerned with the strength of compression - I am looking for something that performs very well and is quick to implement. I would like something simpler than SharpZipLib: something that can be implemented with a couple of short methods.

9条回答
Animai°情兽
2楼-- · 2019-01-09 06:23

I'd suggest looking in the System.IO.Compression Namespace. There's an article on CodeProject that may help.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-09 06:28

I would start with trying one of the existing (free or open source) zip libraries, e.g. http://www.icsharpcode.net/OpenSource/SharpZipLib/

Zip should work well for text strings, and I am not sure if it is worth implementing a compression algorithm yourserlf....

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-09 06:28

You can use deflate algorithm directly, without any headers checksums or footers, as described in this question: Python: Inflate and Deflate implementations

This cuts down a 4100 character URL to 1270 base64 characters, in my test, allowing it to fit inside IE's 2000 limit.

And here's an example of a 4000-character URL, which can't be solved with a hashtable since the applet can exist on any server.

查看更多
登录 后发表回答