CPF/CPF.ReoGrid/Utility/MZipArchive.cs

73 lines
1.2 KiB
C#
Raw Normal View History

2024-06-24 10:15:59 +08:00
using System;
using System.IO;
using System.Linq;
using Ionic.Zip;
namespace CPF.ReoGrid.Utility
{
internal class MZipArchive : IZipArchive
{
private MZipArchive()
{
}
internal static MZipArchive OpenOnStream(Stream stream)
{
return new MZipArchive
{
zip = ZipFile.Read(stream),
stream = stream
};
}
internal static MZipArchive CreateOnStream(Stream stream)
{
return new MZipArchive
{
zip = new ZipFile(),
stream = stream
};
}
public IZipEntry GetFile(string path)
{
ZipEntry zipEntry = this.zip.SingleOrDefault((ZipEntry e) => e.FileName == path);
bool flag = zipEntry == null;
IZipEntry result;
if (flag)
{
result = null;
}
else
{
result = new MZipEntry(zipEntry);
}
return result;
}
public IZipEntry AddFile(string path, Stream stream)
{
return new MZipEntry(this.zip.AddEntry(path, stream));
}
public bool IsFileExist(string path)
{
return this.zip.Any((ZipEntry entry) => entry.FileName == path);
}
public void Flush()
{
this.zip.Save(this.stream);
}
public void Close()
{
this.zip.Dispose();
}
private ZipFile zip;
private Stream stream;
}
}