protected ZipHeader ReadHeader(uint headerBytes, BinaryReader reader) { switch (headerBytes) { case 0x5054b50: return null; case 0x6054b50: { DirectoryEndHeader header3 = new DirectoryEndHeader(); header3.Read(reader); return header3; } case 0x2014b50: { DirectoryEntryHeader header2 = new DirectoryEntryHeader(); header2.Read(reader); return header2; } case 0x4034b50: { LocalEntryHeader entryHeader = new LocalEntryHeader(); entryHeader.Read(reader); this.LoadHeader(entryHeader, reader.BaseStream); this.lastEntryHeader = entryHeader; return entryHeader; } case 0x6064b50: case 0x7064b50: { IgnoreHeader header4 = new IgnoreHeader(ZipHeaderType.Ignore); header4.Read(reader); return header4; } case 0x8074b50: if (FlagUtility.HasFlag<HeaderFlags>(this.lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) { this.lastEntryHeader.Crc = reader.ReadUInt32(); this.lastEntryHeader.CompressedSize = reader.ReadUInt32(); this.lastEntryHeader.UncompressedSize = reader.ReadUInt32(); } else { reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); } return null; case 0x30304b50: return new SplitHeader(); } throw new NotSupportedException("Unknown header: " + headerBytes); }
protected ZipHeader ReadHeader(uint headerBytes, BinaryReader reader) { switch (headerBytes) { case ENTRY_HEADER_BYTES: { var entryHeader = new LocalEntryHeader(); entryHeader.Read(reader); LoadHeader(entryHeader, reader.BaseStream); lastEntryHeader = entryHeader; return entryHeader; } case DIRECTORY_START_HEADER_BYTES: { var entry = new DirectoryEntryHeader(); entry.Read(reader); return entry; } case POST_DATA_DESCRIPTOR: { if (FlagUtility.HasFlag(lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor)) { lastEntryHeader.Crc = reader.ReadUInt32(); lastEntryHeader.CompressedSize = reader.ReadUInt32(); lastEntryHeader.UncompressedSize = reader.ReadUInt32(); } else { reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); } return null; } case DIGITAL_SIGNATURE: return null; case DIRECTORY_END_HEADER_BYTES: { var entry = new DirectoryEndHeader(); entry.Read(reader); return entry; } case SPLIT_ARCHIVE_HEADER_BYTES: { return new SplitHeader(); } case ZIP64_END_OF_CENTRAL_DIRECTORY: case ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR: { var entry = new IgnoreHeader(ZipHeaderType.Ignore); entry.Read(reader); return entry; } default: throw new NotSupportedException("Unknown header: " + headerBytes); } }
internal static IEnumerable<ZipHeader> ReadHeaderNonseekable(Stream stream) { while (true) { ZipHeader header = null; try { MarkingBinaryReader reader = new MarkingBinaryReader(stream); uint headerBytes = reader.ReadUInt32(); switch (headerBytes) { case ENTRY_HEADER_BYTES: { var entry = new LocalEntryHeader(); entry.Read(reader); if (entry.CompressedSize > 0) { entry.PackedStream = new ReadOnlySubStream(stream, entry.CompressedSize, true); } header = entry; } break; case DIRECTORY_START_HEADER_BYTES: { var entry = new DirectoryEntryHeader(); entry.Read(reader); header = entry; } break; case POST_DATA_DESCRIPTOR: case DIGITAL_SIGNATURE: break; case DIRECTORY_END_HEADER_BYTES: { var entry = new DirectoryEndHeader(); entry.Read(reader); header = entry; } break; case ZIP64_END_OF_CENTRAL_DIRECTORY: default: break; } } catch { header = null; } yield return header; } }
internal ZipFilePart(LocalEntryHeader header) { this.Header = header; }