#ZipLib is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform. It is implemented as an assembly (installable in the GAC), and thus can easily be incorporated into other projects (in any .NET language).#ZipLib
was ported from the GNU Classpath ZIP library for use with #Develop (http://www.icsharpcode.net/OpenSource/SD) which needed gzip/zip compression. Later bzip2
compression and tar archiving was added due to popular demand.
官方下载:http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx
ZipLib组件与.net自带的Copression比较,在压缩方面更胜一筹,经过BZip2压缩要小很多,亲手测试,不信你也可以试一试。而且这个功能更加强大。下面就是个人做的一个小例子,具体的应用程序源码:
/Files/yank/Compress.rar。

System;








<summary>


</summary>

class ICSharp




public ICSharp()




//

// TODO: Add constructor logic here

//



/**////
<summary>

/// 压缩

/// </summary>

/// <param name="param"></param>

/// <returns></returns>

public
string Compress(string param)




byte[] data
= System.Text.Encoding.UTF8.GetBytes(param);

//byte[] data = Convert.FromBase64String(param);

= new MemoryStream();

= new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(ms);

try




, data.Length);


finally







return Convert.ToBase64String(ms.ToArray());



/**////
<summary>

/// 解压

/// </summary>

/// <param name="param"></param>

/// <returns></returns>

public
string Decompress(string param)




string commonString="";

byte[] buffer=Convert.FromBase64String(param);

= new MemoryStream(buffer);

= new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(ms);

//这里要指明要读入的格式,要不就有乱码

= new StreamReader(sm,System.Text.Encoding.UTF8);

try






finally







return commonString;


Encoding.UTF8与Convert.FromBase64String
Unicode 标准为所有支持脚本中的每个字符分配一个码位(一个数字)。Unicode 转换格式 (UTF) 是一种码位编码方式。Unicode 标准 3.2 版使用下列 UTF:
UTF-8,它将每个码位表示为一个由 1 至 4 个字节组成的序列。
UTF-16,它将每个码位表示为一个由 1 至 2 个 16 位整数组成的序列。
UTF-32,它将每个码位表示为一个 32 位整数。
Convert.FromBase64String 方法
将指定的 String(它将二进制数据编码为 base 64 数字)转换成等效的 8 位无符号整数数组。
它的参数也又一定的要求:
参数是 由基 64 数字、空白字符和尾随填充字符组成。从零开始以升序排列的以 64 为基的数字为大写字符“A”到“Z”、小写字符“a”到“z”、数字“0”到“9”以及符号“+”和“/”。空白字符为 Tab、空格、回车和换行。s 中可以出现任意数目的空白字符,因为所有空白字符都将被忽略。无值字符“=”用于尾部的空白。s 的末尾可以包含零个、一个或两个填充字符。
异常:
异常类型 | 条件 |
---|---|
ArgumentNullException |
s 为空引用(Visual Basic 中为 Nothing)。 |
FormatException |
s 的长度(忽略空白字符)小于 4。
- 或 - s 的长度(忽略空白字符)不是 4 的偶数倍。 |
s 的长度(忽略空白字符)不是 4 的偶数倍。