#### CL.IO.Zip 是一个基于SharpZipLib的一个压缩和解压的类库,提供给用户在.net环境下使用(VB.NET,C#..等等)当前最新版本为:V1.1.0 百度网盘下载地址:http://pan.baidu.com/s/1qWwZ0LI
做任何操作之前,请使用单例模式,获取ZipHandler对象。
ZipHandler handler = ZipHandler.GetInstance();
##1.压缩
public void PackDirectory(string strDirectory, string zipedFile, ProcessChange changedDG)
var fromDic="E:\ZipTest";\\需要压缩的文件夹路径
var toZip="E:\ZipFile.zip";\\生成压缩包的目标路径
handler.PackDirectory(fromDic, toZip, (num) => { Debug.WriteLine("pack num:" + num); });\\num为百分比,最大为100,可在此处写处理逻辑
public void AddFile(string filePath, string zipPath,string filePathInZip)
var filePath="E:\ReadyToAdd.txt";\\需要添加到压缩包的文件路径
var zipPath="E:\ZipFile.zip";\\压缩包文件路径
handler.AddFile(filePath, zipPath, @"123" + Path.GetFileName(filePath));\\需要添加到压缩包的文件路径
public void AddDirectory(string dicPath,string zipPath,string dicPathInZip,ProcessChange changedDG)
var dicPath="E:\ReadyToAddDic";\\需要添加到压缩包的文件夹路径
var zipPath="E:\ZipFile.zip";\\压缩包文件路径
var dicPathInZip="ReadyToAddDic";\\需要压缩到压缩包内的相对路径,当前值指的是根目录的ReadyToAddDic
handler.IsKeepPath=true;\\保存原路径
handler.AddDirectory(dicPath, zipPath, dicPathInZip,(num) => { Debug.WriteLine("压缩进度:" + num); });
##2.解压
public void UnpackAll(string zipFilePath, string unzipPath, ProcessChange changedDG)
var fromZip="E:\ZipTest.zip";\\需要解压的压缩文件路径
var toDic="E:\ZipFile";\\解压到的文件夹路径
handler.UnpackAll(fromZip, toDic, (num) => { Debug.WriteLine("解压进度:" + num); });
public void UnpackFile(string zipFilePath,string unzipPath,string filePathInZip)
var fromZip="E:\ZipFile.zip";
var toDic="E:\UnZipTest";
handler.UnpackFile(fromZip, toDic, @"models/db.js");
public void UnpackDirectory(string zipFilePath, string unzipPath, string DicPathInZip)
var fromZip="E:\ZipFile.zip";\\压缩包文件路径
var toDic="E:\UnZipTest";
var dicPathInZip="node_modules";
handler.IsKeepPath=true;\\保存原路径
handler.UnpackDirectory(fromZip, toDic, dicPathInZip);