本文整理汇总了C#中ZipEntry.ProcessExtraData方法的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry.ProcessExtraData方法的具体用法?C# ZipEntry.ProcessExtraData怎么用?C# ZipEntry.ProcessExtraData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.ProcessExtraData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadEntries
//.........这里部分代码省略.........
baseStream_.Position = (long)offset64;
long sig64 = ReadLEUint();
if ( sig64 != ZipConstants.Zip64CentralFileHeaderSignature ) {
throw new ZipException(string.Format("Invalid Zip64 Central directory signature at {0:X}", offset64));
}
// NOTE: Record size = SizeOfFixedFields + SizeOfVariableData - 12.
ulong recordSize = ReadLEUlong();
int versionMadeBy = ReadLEUshort();
int versionToExtract = ReadLEUshort();
uint thisDisk = ReadLEUint();
uint centralDirDisk = ReadLEUint();
entriesForThisDisk = ReadLEUlong();
entriesForWholeCentralDir = ReadLEUlong();
centralDirSize = ReadLEUlong();
offsetOfCentralDir = (long)ReadLEUlong();
// NOTE: zip64 extensible data sector (variable size) is ignored.
}
entries_ = new ZipEntry[entriesForThisDisk];
// SFX/embedded support, find the offset of the first entry vis the start of the stream
// This applies to Zip files that are appended to the end of an SFX stub.
// Or are appended as a resource to an executable.
// Zip files created by some archivers have the offsets altered to reflect the true offsets
// and so dont require any adjustment here...
// TODO: Difficulty with Zip64 and SFX offset handling needs resolution - maths?
if ( !isZip64 && (offsetOfCentralDir < locatedEndOfCentralDir - (4 + (long)centralDirSize)) ) {
offsetOfFirstEntry = locatedEndOfCentralDir - (4 + (long)centralDirSize + offsetOfCentralDir);
if (offsetOfFirstEntry <= 0) {
throw new ZipException("Invalid embedded zip archive");
}
}
baseStream_.Seek(offsetOfFirstEntry + offsetOfCentralDir, SeekOrigin.Begin);
for (ulong i = 0; i < entriesForThisDisk; i++) {
if (ReadLEUint() != ZipConstants.CentralHeaderSignature) {
throw new ZipException("Wrong Central Directory signature");
}
int versionMadeBy = ReadLEUshort();
int versionToExtract = ReadLEUshort();
int bitFlags = ReadLEUshort();
int method = ReadLEUshort();
uint dostime = ReadLEUint();
uint crc = ReadLEUint();
long csize = (long)ReadLEUint();
long size = (long)ReadLEUint();
int nameLen = ReadLEUshort();
int extraLen = ReadLEUshort();
int commentLen = ReadLEUshort();
int diskStartNo = ReadLEUshort(); // Not currently used
int internalAttributes = ReadLEUshort(); // Not currently used
uint externalAttributes = ReadLEUint();
long offset = ReadLEUint();
byte[] buffer = new byte[Math.Max(nameLen, commentLen)];
StreamUtils.ReadFully(baseStream_, buffer, 0, nameLen);
string name = ZipConstants.ConvertToStringExt(bitFlags, buffer, nameLen);
ZipEntry entry = new ZipEntry(name, versionToExtract, versionMadeBy, (CompressionMethod)method);
entry.Crc = crc & 0xffffffffL;
entry.Size = size & 0xffffffffL;
entry.CompressedSize = csize & 0xffffffffL;
entry.Flags = bitFlags;
entry.DosTime = (uint)dostime;
entry.ZipFileIndex = (long)i;
entry.Offset = offset;
entry.ExternalFileAttributes = (int)externalAttributes;
if ((bitFlags & 8) == 0) {
entry.CryptoCheckValue = (byte)(crc >> 24);
}
else {
entry.CryptoCheckValue = (byte)((dostime >> 8) & 0xff);
}
if (extraLen > 0) {
byte[] extra = new byte[extraLen];
StreamUtils.ReadFully(baseStream_, extra);
entry.ExtraData = extra;
}
entry.ProcessExtraData(false);
if (commentLen > 0) {
StreamUtils.ReadFully(baseStream_, buffer, 0, commentLen);
entry.Comment = ZipConstants.ConvertToStringExt(bitFlags, buffer, commentLen);
}
entries_[i] = entry;
}
}
示例2: GetNextEntry
//.........这里部分代码省略.........
header == ZipConstants.ArchiveExtraDataSignature ||
header == ZipConstants.Zip64CentralFileHeaderSignature) {
// No more individual entries exist
Close();
return null;
}
// -jr- 07-Dec-2003 Ignore spanning temporary signatures if found
// Spanning signature is same as descriptor signature and is untested as yet.
if ( (header == ZipConstants.SpanningTempSignature) || (header == ZipConstants.SpanningSignature) ) {
header = inputBuffer.ReadLeInt();
}
if (header != ZipConstants.LocalHeaderSignature) {
throw new ZipException("Wrong Local header signature: 0x" + String.Format("{0:X}", header));
}
short versionRequiredToExtract = (short)inputBuffer.ReadLeShort();
flags = inputBuffer.ReadLeShort();
method = inputBuffer.ReadLeShort();
uint dostime = (uint)inputBuffer.ReadLeInt();
int crc2 = inputBuffer.ReadLeInt();
csize = inputBuffer.ReadLeInt();
size = inputBuffer.ReadLeInt();
int nameLen = inputBuffer.ReadLeShort();
int extraLen = inputBuffer.ReadLeShort();
bool isCrypted = (flags & 1) == 1;
byte[] buffer = new byte[nameLen];
inputBuffer.ReadRawBuffer(buffer);
string name = ZipConstants.ConvertToStringExt(flags, buffer);
entry = new ZipEntry(name, versionRequiredToExtract);
entry.Flags = flags;
entry.CompressionMethod = (CompressionMethod)method;
if ((flags & 8) == 0) {
entry.Crc = crc2 & 0xFFFFFFFFL;
entry.Size = size & 0xFFFFFFFFL;
entry.CompressedSize = csize & 0xFFFFFFFFL;
entry.CryptoCheckValue = (byte)((crc2 >> 24) & 0xff);
} else {
// This allows for GNU, WinZip and possibly other archives, the PKZIP spec
// says these values are zero under these circumstances.
if (crc2 != 0) {
entry.Crc = crc2 & 0xFFFFFFFFL;
}
if (size != 0) {
entry.Size = size & 0xFFFFFFFFL;
}
if (csize != 0) {
entry.CompressedSize = csize & 0xFFFFFFFFL;
}
entry.CryptoCheckValue = (byte)((dostime >> 8) & 0xff);
}
entry.DosTime = dostime;
// If local header requires Zip64 is true then the extended header should contain
// both values.
// Handle extra data if present. This can set/alter some fields of the entry.
if (extraLen > 0) {
byte[] extra = new byte[extraLen];
inputBuffer.ReadRawBuffer(extra);
entry.ExtraData = extra;
}
entry.ProcessExtraData(true);
if ( entry.CompressedSize >= 0 ) {
csize = entry.CompressedSize;
}
if ( entry.Size >= 0 ) {
size = entry.Size;
}
if (method == (int)CompressionMethod.Stored && (!isCrypted && csize != size || (isCrypted && csize - ZipConstants.CryptoHeaderSize != size))) {
throw new ZipException("Stored, but compressed != uncompressed");
}
// Determine how to handle reading of data if this is attempted.
if (entry.IsCompressionMethodSupported()) {
internalReader = new ReadDataHandler(InitialRead);
} else {
internalReader = new ReadDataHandler(ReadingNotSupported);
}
return entry;
}