本文整理汇总了C#中ZipEntry.Compare方法的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry.Compare方法的具体用法?C# ZipEntry.Compare怎么用?C# ZipEntry.Compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.Compare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
public byte[] Extract(bool Preview, String outname = null)
{
byte[] databuff;
int dataoff = 30; // For ZipEntry header - not the above one
if (Filename != null)
dataoff += Filename.Length;
if (Extra != null)
dataoff += Extra.Length;
// KFreon: Use stored MemoryStream if possible.
Stream tpf = null;
if (_par.FileData == null)
tpf = new FileStream(_par._filename, FileMode.Open, FileAccess.Read);
else
tpf = new MemoryStream(_par.FileData);
tpf.Seek(FileOffset, SeekOrigin.Begin);
databuff = ZipReader.BuffXOR(tpf, dataoff + (int)ComprSize + 16); // XOR the whole data block as well as the footer
// KFreon: Dispose of stream IF it was a FileStream
if (_par.FileData == null)
tpf.Dispose();
// Check for correct header data and such
ZipEntry fileentry = new ZipEntry(databuff);
if (!fileentry.Compare(this))
throw new InvalidDataException("File header not as expected");
// KFreon: Apparently not necessary. Some TPF's fail to load with this, but when commented out, they load fine, so...
/*if (BitConverter.ToUInt32(databuff, (int)ComprSize + dataoff) != datadescriptormagic)
Console.WriteLine("Footer not as expected");*/
databuff = ZipDecrypto.DecryptData(this, databuff, dataoff, (int)ComprSize);
databuff = Deflate(databuff, 12 + dataoff, (int)ComprSize - 12);
if (databuff.Length != UncomprSize)
throw new InvalidDataException("Deflation resulted in incorrect file size");
if (CRC32.BlockChecksum(databuff, 0, (int)UncomprSize) != CRC)
throw new InvalidDataException("Checksums don't match");
if (!Preview)
{
outname = outname ?? Filename;
using (FileStream fs = new FileStream(outname, FileMode.Create, FileAccess.Write))
{
fs.Write(databuff, 0, (int)UncomprSize);
}
return null;
}
else
return databuff;
}
示例2: Extract
public byte[] Extract(bool Preview, String outname = null)
{
byte[] databuff;
int dataoff = 30;
if (Filename != null)
dataoff += Filename.Length;
if (Extra != null)
dataoff += Extra.Length;
using (FileStream tpf = new FileStream(_par._filename, FileMode.Open, FileAccess.Read))
{
tpf.Seek(FileOffset, SeekOrigin.Begin);
databuff = ZipReader.BuffXOR(tpf, dataoff + (int)ComprSize + 16); // XOR the whole data block as well as the footer
}
// Check for correct header data and such
ZipEntry fileentry = new ZipEntry(databuff);
if (!fileentry.Compare(this))
throw new InvalidDataException("File header not as expected");
if (BitConverter.ToUInt32(databuff, (int)ComprSize + dataoff) != datadescriptormagic)
throw new InvalidDataException("Footer not as expected");
//ZipCrypto.DecryptData(this, databuff, dataoff, (int)ComprSize);
KFreonZipCrypto crypto = new KFreonZipCrypto(this, databuff, dataoff, (int)ComprSize);
databuff = crypto.GetBlocks();
databuff = Deflate(databuff, 12 + dataoff, (int)ComprSize - 12);
if (databuff.Length != UncomprSize)
throw new InvalidDataException("Deflation resulted in incorrect file size");
CRC32 crcgen = new CRC32();
if (crcgen.BlockChecksum(databuff, 0, (int)UncomprSize) != CRC)
throw new InvalidDataException("Checksums don't match");
if (!Preview)
{
outname = outname ?? Filename;
using (FileStream fs = new FileStream(outname, FileMode.Create, FileAccess.Write))
{
fs.Write(databuff, 0, (int)UncomprSize);
}
return null;
}
else
return databuff;
}