使用 ICSharpCode.SharpZipLib.dll 压缩文件 方法实例
来源:互联网 发布:mindnode windows版 编辑:程序博客网 时间:2024/05/21 22:38
/// <summary>
/// 使用 ICSharpCode.SharpZipLib.dll 压缩文件 方法实例
/// </summary>
/// <param name="FileToZip">需要被压缩的文件路径</param>
/// <param name="ZipedFile">压缩后(zip)文件路径</param>
/// <param name="filename">压缩包内文件的名称</param>
/// <param name="CompressionLevel">压缩级数(0-9)</param>
/// <param name="BlockSize">单次读取字节数(2048/4096/..)</param>
public void ZipFile(string FileToZip, string ZipedFile, string filename, int CompressionLevel, int BlockSize)
{
System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
ZipEntry ZipEntry = new ZipEntry(filename);
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(CompressionLevel);
byte[] buffer = new byte[BlockSize];
System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, size);
try
{
while (size < StreamToZip.Length)
{
int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, sizeRead);
size += sizeRead;
}
}
catch (System.Exception ex)
{
throw ex;
}
ZipStream.Finish();
ZipStream.Close();
StreamToZip.Close();
/// 使用 ICSharpCode.SharpZipLib.dll 压缩文件 方法实例
/// </summary>
/// <param name="FileToZip">需要被压缩的文件路径</param>
/// <param name="ZipedFile">压缩后(zip)文件路径</param>
/// <param name="filename">压缩包内文件的名称</param>
/// <param name="CompressionLevel">压缩级数(0-9)</param>
/// <param name="BlockSize">单次读取字节数(2048/4096/..)</param>
public void ZipFile(string FileToZip, string ZipedFile, string filename, int CompressionLevel, int BlockSize)
{
System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
ZipEntry ZipEntry = new ZipEntry(filename);
ZipStream.PutNextEntry(ZipEntry);
ZipStream.SetLevel(CompressionLevel);
byte[] buffer = new byte[BlockSize];
System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, size);
try
{
while (size < StreamToZip.Length)
{
int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
ZipStream.Write(buffer, 0, sizeRead);
size += sizeRead;
}
}
catch (System.Exception ex)
{
throw ex;
}
ZipStream.Finish();
ZipStream.Close();
StreamToZip.Close();
}
- 使用 ICSharpCode.SharpZipLib.dll 压缩文件 方法实例
- C#使用ICSharpCode.SharpZipLib压缩文件
- C#使用ICSharpCode.SharpZipLib压缩文件
- C#使用ICSharpCode.SharpZipLib压缩文件
- C#使用ICSharpCode.SharpZipLib压缩文件
- C#利用ICSharpCode.SharpZipLib.dll压缩文件
- ASP.NET生成压缩文件(rar打包)ICSharpCode.SharpZipLib.dll
- C#利用ICSharpCode.SharpZipLib.dll压缩文件和解压文件
- (转载)C#利用ICSharpCode.SharpZipLib.dll压缩文件和解压文件
- 使用ICSharpCode.SharpZipLib.dll实现在线解压缩
- 使用ICSharpCode.SharpZipLib.dll实现在线解压缩
- 使用ICSharpCode.SharpZipLib.dll实现在线解压缩
- 使用ICSharpCode.SharpZipLib.dll解压指定文件
- ICSharpCode.SharpZipLib.dll 使用方法
- ICSharpCode.SharpZipLib 使用演示
- ICSharpCode.SharpZipLib 初级使用
- ICSharpCode.SharpZipLib 初级使用
- ICSharpCode.SharpZipLib.Zip 使用
- Fedora5下配置MySQL (很有参考价值的 MySQL资料 包括如何在Linux文件系统移动MySQL数据库的位置)
- 个人开公司的流程
- Android 近百个项目的源代码
- pads layout的一些常用快捷
- ASP.NET页面间数据传递的方法
- 使用 ICSharpCode.SharpZipLib.dll 压缩文件 方法实例
- Windows下调试应用程序堆栈破坏的方法(内存OX****F不能为Read/Write)
- 原型模式--Prototype
- ffmpeg 从mp4上提取H264的nalu
- c# 使用GZipStream压缩和解压流
- centos下彻底删掉SElinux的方法
- ZooKeeper-3.3.4集群安装配置
- 编程语言汽车
- zoj3499--Median//qsort