本文整理汇总了C#中Ionic.Zip.ZipEntry类的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry类的具体用法?C# ZipEntry怎么用?C# ZipEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ZipEntry类属于Ionic.Zip命名空间,在下文中一共展示了ZipEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreEqual
private bool AreEqual(ZipEntry approvedEntry, ZipEntry receivedEntry)
{
if (approvedEntry.IsDirectory && receivedEntry.IsDirectory)
{
return true;
}
using (var approvedStream = new MemoryStream())
{
using (var receivedStream = new MemoryStream())
{
approvedEntry.Extract(approvedStream);
receivedEntry.Extract(receivedStream);
var approvedBytes = approvedStream.ToArray();
var receivedBytes = receivedStream.ToArray();
var areEqual = approvedBytes == receivedBytes;
for (int i = 0; i < receivedBytes.Length && i < approvedBytes.Length; i++)
{
if (receivedBytes[i] != approvedBytes[i])
{
Logger.Event("Failed on {0}[{1}] '{2}' != '{3}'", receivedEntry.FileName, i,
(char) receivedBytes[i], (char) approvedBytes[i]);
return false;
}
}
return true;
}
}
}
示例2: Handle
protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
{
string orig = entry.FileName;
string stripped = GetStripped(entry.FileName);
if (stripped == null)
{
if (entry.IsDirectory)
{
zip.RemoveEntry(entry);
return OperationResult.Removed;
}
stripped = orig;
}
try
{
entry.FileName = stripped;
return OperationResult.Changed;
}
catch (Exception ex)
{
string type = entry.IsDirectory ? "directory" : "file";
throw new Exception(string.Format("Could not rename {0} '{1}' to '{2}'", type, orig, stripped), ex);
}
}
示例3: ZipPackagePart
internal ZipPackagePart(ZipPackage package, ZipEntry entry)
{
Package = package;
Entry = entry;
SaveHandler = null;
Uri = new Uri(package.GetUriKey(entry.FileName), UriKind.Relative);
}
示例4: GetEntryMemoryStream
public MemoryStream GetEntryMemoryStream(ZipEntry zipEntry)
{
var stream = new MemoryStream();
zipEntry.Extract(stream);
stream.Position = 0;
return stream;
}
示例5: LoadBitmap
private static Bitmap LoadBitmap(ZipEntry zipEntry)
{
MemoryStream stream = new MemoryStream();
zipEntry.Extract(stream);
stream.Position = 0;
Bitmap result = new Bitmap(stream);
stream.Dispose();
return result;
}
示例6: EmlParser
/// <summary>
/// Constructors
/// </summary>
/// <param name="ze"></param>
public EmlParser(ZipEntry ze)
{
try
{
parseEML(ze);
}
catch (Exception ex)
{ throw ex; }
}
示例7: Create
public static PartWrapper Create(ZipEntry part)
{
if (part.IsZip())
{
return new ZipPartWrapper(part);
}
return new PartWrapper(part);
}
示例8: SetZipFile
private static void SetZipFile(ZipEntry zipEntry, ZipFileInfo file)
{
if (!string.IsNullOrEmpty(file.Password))
zipEntry.Password = file.Password;
zipEntry.Comment = file.Comment;
zipEntry.CompressionMethod = (Ionic.Zip.CompressionMethod)((int)file.CompressionMethod);
zipEntry.CompressionLevel = (Ionic.Zlib.CompressionLevel)((int)file.CompressionLevel);
}
示例9: Check
public void Check()
{
// Is there a valid input stream
if (_stream == null)
throw new FileNotFoundException("No valid file");
// Now read gwz file and save for later use
_zip = ZipFile.Read(_stream);
if (_zip == null)
throw new FileLoadException("No valid gwz file");
foreach(ZipEntry zipEntry in _zip.Entries)
{
switch(Path.GetExtension(zipEntry.FileName).ToLower())
{
case ".lua":
_luaFile = zipEntry;
_luaFiles += 1;
break;
}
}
// Is there a Lua file?
if (_luaFile == null)
throw new FileNotFoundException("No valid Lua file found");
// Is there more than one Lua file
if (_luaFiles > 1)
throw new FileLoadException("More than one Lua file found");
// Any compilation errors of the Lua file
LUA.Check(_zip[_luaFile.FileName].OpenReader(), _luaFile.FileName);
// Extract cartridge data from Lua file
cartridge = LUA.Extract(_zip[_luaFile.FileName].OpenReader());
// Save Lua file name for later use
cartridge.LuaFileName = _luaFile.FileName;
// Now check, if all media resources files exist
foreach(Media media in cartridge.Medias) {
foreach(MediaResource resource in media.Resources) {
// Check, if filename is in list of files
if (!_zip.EntryFileNames.Contains(resource.Filename))
{
if (string.IsNullOrWhiteSpace(resource.Filename))
throw new FileNotFoundException("The Lua file is referencing a file without a filename");
else
throw new FileNotFoundException(String.Format("The GWZ is missing a file referred to by the cartridge's code. The file name is: {0}", resource.Filename));
}
}
}
// Now all is checked without any problems
// So it seams, that this GWZ file is valid
}
示例10: Handle
protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
{
if (entry.IsDirectory && (entry.Attributes & FileAttributes.Directory) != FileAttributes.Directory)
{
entry.Attributes |= FileAttributes.Directory;
}
// This just helps if a file is resaved. It shouldn't be treated as modified if this cleans something up.
return OperationResult.NoChange;
}
示例11: Handle
protected override OperationResult Handle(ZipEntry entry, ZipFile zip)
{
if (_regex.IsMatch(entry.FileName))
{
zip.RemoveEntry(entry);
return OperationResult.Removed;
}
return OperationResult.NoChange;
}
示例12: ContentSection
public ContentSection(ZipEntry entry)
{
Id = Path.GetFileNameWithoutExtension(entry.FileName);
ArchivePath = entry.FileName;
using (Stream s = entry.OpenReader())
{
using (StreamReader sr = new StreamReader(s))
{
Content = sr.ReadToEnd();
}
}
}
示例13: ExtractFileToStream
public static MemoryStream ExtractFileToStream(string zipSource, string filePath)
{
MemoryStream stream = new MemoryStream();
using (ZipFile zip = ZipFile.Read(zipSource))
{
var matchFile = new ZipEntry();
foreach (var file in zip.Where(file => file.FileName == filePath))
matchFile = file;
matchFile.Extract(stream);
}
return stream;
}
示例14: ExtractFileFromStream
public static string ExtractFileFromStream(ZipEntry entry)
{
var reader = new MemoryStream();
entry.Extract(reader);
reader = new MemoryStream(reader.ToArray());
var streamReader = new StreamReader(reader);
var text = streamReader.ReadToEnd();
reader.Dispose();
return text;
}
示例15: ForRead
public static ZipCrypto ForRead(string password, ZipEntry e)
{
System.IO.Stream s = e._archiveStream;
e._WeakEncryptionHeader = new byte[12];
byte[] eh = e._WeakEncryptionHeader;
ZipCrypto z = new ZipCrypto();
if (password == null)
throw new BadPasswordException("This entry requires a password.");
z.InitCipher(password);
ZipEntry.ReadWeakEncryptionHeader(s, eh);
// Decrypt the header. This has a side effect of "further initializing the
// encryption keys" in the traditional zip encryption.
byte[] DecryptedHeader = z.DecryptMessage(eh, eh.Length);
// CRC check
// According to the pkzip spec, the final byte in the decrypted header
// is the highest-order byte in the CRC. We check it here.
if (DecryptedHeader[11] != (byte)((e._Crc32 >> 24) & 0xff))
{
// In the case that bit 3 of the general purpose bit flag is set to
// indicate the presence of an 'Extended File Header' or a 'data
// descriptor' (signature 0x08074b50), the last byte of the decrypted
// header is sometimes compared with the high-order byte of the
// lastmodified time, rather than the high-order byte of the CRC, to
// verify the password.
//
// This is not documented in the PKWare Appnote.txt.
// This was discovered this by analysis of the Crypt.c source file in the InfoZip library
// http://www.info-zip.org/pub/infozip/
if ((e._BitField & 0x0008) != 0x0008)
{
throw new BadPasswordException("The password did not match.");
}
else if (DecryptedHeader[11] != (byte)((e._TimeBlob >> 8) & 0xff))
{
throw new BadPasswordException("The password did not match.");
}
// We have a good password.
}
else
{
// A-OK
}
return z;
}