73 lines
1.2 KiB
C#
73 lines
1.2 KiB
C#
![]() |
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;
|
|||
|
}
|
|||
|
}
|