C#解压缩

.Net技术 码拜 8年前 (2016-05-19) 1617次浏览
 public void UnZip(string vToPath, string vPwd)
{
if (string.IsNullOrEmpty(vToPath))
{
return;
}
if (!Directory.Exists(vToPath) || !File.Exists(this.ZipFile))
{
Directory.CreateDirectory(vToPath);
}
long vTotal = new FileInfo(this.ZipFile).Length;
long vPos = 0;
ZipInfo vZipInfo = null;
ByteHelper bByteUtil = new ByteHelper();
using (ZipInputStream s = new ZipInputStream(File.OpenRead(this.ZipFile)))
{
if (!string.IsNullOrEmpty(vPwd))
{
s.Password = vPwd;
}
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string zipDirectory = Path.GetDirectoryName(theEntry.Name);
string zipFile = Path.GetFileName(theEntry.Name);
string vDirectory = Path.Combine(vToPath, zipDirectory);
string vFile = Path.Combine(vDirectory, zipFile);
long vNowSize = theEntry.Size;
vPos = s.Position;
vZipInfo = new ZipInfo(vDirectory, vFile, vNowSize, vPos, vTotal);
this.Trigger(this.ItemZiping, vZipInfo, true);
// 创建目录
if (!string.IsNullOrEmpty(zipDirectory) && !Directory.Exists(vDirectory))
{
Directory.CreateDirectory(vDirectory);
}
if (string.IsNullOrEmpty(zipFile))
{
continue;
}
//存在则删除文件
if (File.Exists(vFile))
{
File.Delete(vFile);
}
//创建文件
using (FileStream fs = File.Create(vFile))
{
bByteUtil.CopyStream(s, fs);
}
vPos = s.Position;
vZipInfo = new ZipInfo(vDirectory, vFile, vNowSize, vPos, vTotal);
this.Trigger(this.ItemZiped, vZipInfo, true);
}
}
this.Trigger(this.Ziped, vZipInfo, true);
}
这是一份解压缩的源码,本人想问一下   ZipEntry theEntry这是什么?还有theEntry = s.GetNextEntry())都为空意味着什么?急
解决方案

80

zipentry翻译成中文也就是压缩入口,用于获取被压缩的文件,getnext就是获取下一个,假如返回null表示没文件了

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C#解压缩
喜欢 (0)
[1034331897@qq.com]
分享 (0)