非常简单的短字符串COM pression [英] Really simple short string compression

查看:95
本文介绍了非常简单的短字符串COM pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有字符串最大长度(约255个字符是的,我COM pressing的网址)?

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

我不关心与COM pression的实力 - 我要找的东西,表现得非常好,并快速实施。我想的东西比简单的 SharpZipLib :在一些可以与一对夫妇实施短方法。

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.

推荐答案

我觉得这里的关键问题是你为什么要COM preSS网址吗?

I think the key question here is "Why do you want to compress URLs?"

试图缩短长URL地址栏?

你更好的存储原始网址的地方(数据库,文本文件...)旁边的非域部分的哈希值code(MD5是罚款)。那么你可以有一个简单的页面(或某些HTTP模块如果你感觉华而不实)来读取MD5和查找实际的URL。这是TinyURL的和其他人是如何工作的。

You're better storing the original URL somewhere (database, text file ...) alongside a hashcode of the non-domain part (MD5 is fine). You can then have a simple page (or some HTTPModule if you're feeling flashy) to read the MD5 and lookup the real URL. This is how TinyURL and others work.

例如:

http://mydomain.com/folder1/folder2/page1.aspx

可缩短至:

http://mydomain.com/2d4f1c8a

使用COM pression库,这将不起作用的。该字符串将COM pressed成一个较短的二进制重新presentation,但转换这回它必须是一个有效的URL(如Base64编码)组成部分的字符串会抵消你从COM $获得任何好处p $ pssion。

Using a compression library for this will not work. The string will be compressed into a shorter binary representation, but converting this back to a string which needs to be valid as part of a URL (e.g. Base64) will negate any benefit you gained from the compression.

存储大量网址在内存或磁盘上?

使用内置的COM pressing库中System.IO.Com pression或zlib库既简单又令人难以置信的好。既然你要存储二进制数据的COM pressed输出将被罚款原样。你需要uncom preSS它用它作为一个URL。

Use the built in compressing library within System.IO.Compression or the ZLib library which is simple and incredibly good. Since you will be storing binary data the compressed output will be fine as-is. You'll need to uncompress it to use it as a URL.

这篇关于非常简单的短字符串COM pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆