20080902 c# bzip
CSDN技术中心 在C#中利用SharpZipLib进行文件的压缩和解压缩
http://dev.csdn.net/article/63929.shtm
ICSharpCode.SharpZipLib.BZip2
http://www.componentspot.com/doccenter/SharpZipLib/icsharpcode.sharpziplib.bzip2.html
[翻译]用SharpZipLib(#ZipLib)压缩MemoryStream – 云和山的彼端 – 博客园
http://www.cnblogs.com/jecray/archive/2007/04/15/sharpziplib.html
X3BLOG 多用户版 1.0.0 beta1 /src/SyCODE.Component/Compress.cs
http://www.muchool.com/project/X3BLOG_DYHB/1.0.0+beta1/src/sycode.component/compress.54A17766.cs
Blog
http://cache.baidu.com/c?m=9d78d513d99309f41afa950e0d01d717580ed3237e9f8b57218fc35f93150416183ba3f03023604595852b345ebb0e1cb4ff6c34714137b6e8d595128aead27b649f2743315ed51045920eafbc187e8577875a9efe44b8a7a665c7fd958d994353bd004438cae78a2e1713be3ef21726e4d2c916480a52e9ad7672fe2f2777c2761fe318bff7326a1086828c4b4db57a8e3c44d5fc75f62912b14ff3555d4619e10aa609276070a71830ff407f59d3ad3f9d3d783672ea09a4b9c2c0eb428caaea45eb89c8aa2f916becc1fdf972437752&p=8b2a900d84d811a05fed8c624b07&user=baidu
我们创建一个BZip2 output stream对象,容纳MemoryStream.
BZip2OutputStream zosCompressed = new BZip2OutputStream(msCompressed);
现在我来解说上面报头的含义.在我的实际测试中使,用GZip时,压缩1字节数据需要28字节的额外报头,那些额外的字节是不能被压缩的.用BZip2时,需要36字节的额外报头.实际上,用BZip2可以压缩一个12892字节的源文件到2563字节,有大概75%的压缩率.另一个测试是从730字节压缩到429字节,最后一个测试是174字节到161字节.显然,任何压缩需要额外的可用空间.
下面我们将数据写入BZip2OutputStream
string sBuffer = "This represents some data being compressed."
byte[] bytesBuffer = Encoding.ASCII.GetBytes(sBuffer);
zosCompressed.Write(bytesBuffer, 0, bytesBuffer.Length);
zosCompressed.Finalize();
zosCompressed.Close();
由于要用到IO和stream方法,要使用字节数组替代字符串.所以我们用字节数组作为输出,然后将压缩的流写入内存流.
bytesBuffer = msCompressed.ToArray();
string sCompressed = Encoding.ASCII.GetString(bytesBuffer);
这样内存流中包含了压缩过的数据,我们将数据用字符数组输出,然后转换成字符串.要注意,这个字符串是乱码,不可读的.如果你想查看数据,我用的方法是把它转换为Base64编码的数据,但是这样会增加大小.运行程序使43字节的未压缩数据变成74字节的压缩数据,如果用base 64编码,会得到100字节的结果:
QlpoOTFBWSZTWZxkIpsAAAMTgEABBAA+49wAIAAxTTIxMTEImJhNNDIbvQ
aWyYEHiwN49LdoKNqKN2C9ZUG5+LuSKcKEhOMhFNg=
解压缩
MemoryStream msUncompressed =
new MemoryStream(Encoding.ASCII.GetBytes(sCompressed));
BZip2InputStream zisUncompressed = new BZip2InputStream(msUncompressed);
bytesBuffer = new byte[zisUncompressed.Length];
zisUncompressed.Read(bytesBuffer, 0, bytesBuffer.Length);
zisUncompressed.Close();
msUncompressed.Close();
string sUncompressed = Encoding.ASCII.GetString(bytesBuffer);
这样sUncompressed将被解压到原始的字符串.文件也是相同的原理.
今日百度招聘有感 – 云和山的彼端 – CSDNBlog
http://blog.csdn.net/jecray/archive/2007/04/06/1554578.aspx
字符串(string)压缩 .NET技术 / C# – CSDN社区 community.csdn.net
http://topic.csdn.net/t/20060214/14/4555387.html
//压缩
public static string Compress(string uncompressedString)
&leftsign;
byte[] bytData = System.Text.Encoding.Unicode.GetBytes(uncompressedString);
MemoryStream ms = new MemoryStream();
Stream s = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(ms);
s.Write(bytData, 0, bytData.Length);
s.Close();
byte[] compressedData = (byte[])ms.ToArray();
return System.Convert.ToBase64String(compressedData, 0, compressedData.Length);
&rightsign;
//解压
public static string DeCompress(string compressedString)
&leftsign;
System.Text.StringBuilder uncompressedString = new System.Text.StringBuilder();
int totalLength = 0;
byte[] bytInput = System.Convert.FromBase64String(compressedString);;
byte[] writeData = new byte[4096];
Stream s2 = new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(new MemoryStream(bytInput));
while (true)
&leftsign;
int size = s2.Read(writeData, 0, writeData.Length);
if (size > 0)
&leftsign;
totalLength += size;
uncompressedString.Append(System.Text.Encoding.Unicode.GetString(writeData,0,size));
&rightsign;
else
&leftsign;
break;
&rightsign;
&rightsign;
s2.Close();
return uncompressedString.ToString();
&rightsign;
compression helper…improved version (SharpZipLib)
http://www.xmlasp.net/n1492c13.aspx
使用ICSharpCode.SharpZipLib.dll实现在线解压缩_程序员之家
http://hi.baidu.com/xiao_wei2008/blog/item/307a881fa80dee66f624e422.html
在C#中怎么利用SharpZipLib进行字符串的压缩和解压缩
http://topic.csdn.net/u/20070307/18/8a96353a-cf0a-406c-80f4-255a1ef92a29.html
http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx
In a Class of its own – the .NET Zip Library
http://www.aspheute.com/english/20011115.asp
Sipo Blog-ASP.NET下Zip,GZip,BZip2,Tar的实时压缩与解压缩
http://www.dc9.cn/view.asp?id=332
历史博文
- 20070727 计算机 期刊 投稿 审稿费 时效性 潜规则 - 2008
- 1127 TAPI 资料 - 2007
- 0210 版本控制软件大全 SVK - 2006
- 70G的VNC LOG+LINUX ORACLE编程调研 - 2005
- SetupFactory7安装包制作-背景音乐 - 2005
- VS.NET部署安装和SETUPFACTORY7.0 - 2005
- 32bit fax接收传真CLASS2 - 2005
- 32bit fax发送传真CLASS2 - 2005
Hi, Congratulations to the site owner for this marvelous work you’ve done. It has lots of useful and interesting data.