您好,欢迎光临本网站![请登录][注册会员]  
文件名称: SharpZipLib .net压缩库
  所属分类: C#
  开发工具:
  文件大小: 228kb
  下载次数: 0
  上传时间: 2010-03-23
  提 供 者: tlo***
 详细说明: .net压缩库 SharpZipLib,支持net1.1、net2.0、netCF2.0框架,下面是用法示例: using System; using System.Text; using System.IO; using ICSharpCode.SharpZipLib; namespace SerializableJob.Compression { public enum CompressionType { GZip, BZip2, Zip } public class Compression { public static CompressionType CompressionProvider = CompressionType.GZip; private static Stream OutputStream(Stream inputStream) { switch (CompressionProvider) { case Comp ressionType.BZip2: return new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(inputStream); case CompressionType.GZip: return new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(inputStream); case CompressionType.Zip: return new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(inputStream); default: return new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(inputStream); } } private static Stream InputStream(Stream inputStream) { switch (CompressionProvider) { case CompressionType.BZip2: return new ICSharpCode.SharpZipLib.BZip2.BZip2InputStream(inputStream); case CompressionType.GZip: return new ICSharpCode.SharpZipLib.GZip.GZipInputStream(inputStream); case CompressionType.Zip: return new ICSharpCode.SharpZipLib.Zip.ZipInputStream(inputStream); default: return new ICSharpCode.SharpZipLib.GZip.GZipInputStream(inputStream); } } public static byte[] Compress(byte[] bytesToCompress) { MemoryStream ms = new MemoryStream(); Stream s = OutputStream(ms); s.Write(bytesToCompress, 0, bytesToCompress.Length); s.Close(); return ms.ToArray(); } public static string Compress(string stringToCompress) { byte[] compressedData = CompressToByte(stringToCompress); string strOut = Convert.ToBase64String(compressedData); return strOut; } public static byte[] CompressToByte(string stringToCompress) { byte[] bytData = Encoding.Unicode.GetBytes(stringToCompress); return Compress(bytData); } public string DeCompress(string stringToDecompress) { string outString = string.Empty; if (stringToDecompress == null) { throw new ArgumentNullException(stringToDecompress, "You tried to use an empty string"); } try { byte[] inArr = Convert.FromBase64String(stringToDecompress.Trim()); outString = System.Text.Encoding.Unicode.GetString(DeCompress(inArr)); } catch (NullReferenceException nEx) { return nEx.Message; } return outString; } public static byte[] DeCompress(byte[] bytesToDecompress) { byte[] writeData = new byte[4096]; Stream s2 = InputStream(new MemoryStream(bytesToDecompress)); MemoryStream outStream = new MemoryStream(); while (true) { int size = s2.Read(writeData, 0, writeData.Length); if (size > 0) { outStream.Write(writeData, 0, size); } else { break; } } s2.Close(); byte[] outArr = outStream.ToArray(); outStream.Close(); return outArr; } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: SharpZipLib 压缩库
 输入关键字,在本站1000多万海量源码库中尽情搜索: