コード例 #1
0
        protected ZipHeader?ReadHeader(uint headerBytes, BinaryReader reader, bool zip64 = false)
        {
            switch (headerBytes)
            {
            case ENTRY_HEADER_BYTES:
            {
                var entryHeader = new LocalEntryHeader(_archiveEncoding);
                entryHeader.Read(reader);
                LoadHeader(entryHeader, reader.BaseStream);

                _lastEntryHeader = entryHeader;
                return(entryHeader);
            }

            case DIRECTORY_START_HEADER_BYTES:
            {
                var entry = new DirectoryEntryHeader(_archiveEncoding);
                entry.Read(reader);
                return(entry);
            }

            case POST_DATA_DESCRIPTOR:
            {
                if (FlagUtility.HasFlag(_lastEntryHeader !.Flags, HeaderFlags.UsePostDataDescriptor))
                {
                    _lastEntryHeader.Crc              = reader.ReadUInt32();
                    _lastEntryHeader.CompressedSize   = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32();
                    _lastEntryHeader.UncompressedSize = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32();
                }
コード例 #2
0
        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);
        }
コード例 #3
0
        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:
            default:
                throw new NotSupportedException("Unknown header: " + headerBytes);
            }
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        internal LocalEntryHeader GetLocalHeader(Stream stream, DirectoryEntryHeader directoryEntryHeader)
        {
            stream.Seek((long)directoryEntryHeader.RelativeOffsetOfEntryHeader, SeekOrigin.Begin);
            BinaryReader     reader      = new BinaryReader(stream);
            uint             headerBytes = reader.ReadUInt32();
            LocalEntryHeader header      = base.ReadHeader(headerBytes, reader) as LocalEntryHeader;

            if (header == null)
            {
                throw new InvalidOperationException();
            }
            return(header);
        }
コード例 #6
0
        protected ZipHeader ReadHeader(uint headerBytes, BinaryReader reader, bool zip64 = false)
        {
            switch (headerBytes)
            {
            case ENTRY_HEADER_BYTES:
            {
                var entryHeader = new LocalEntryHeader(_archiveEncoding);
                entryHeader.Read(reader);
                LoadHeader(entryHeader, reader.BaseStream);

                _lastEntryHeader = entryHeader;
                return(entryHeader);
            }

            case DIRECTORY_START_HEADER_BYTES:
            {
                var entry = new DirectoryEntryHeader(_archiveEncoding);
                entry.Read(reader);
                return(entry);
            }

            case POST_DATA_DESCRIPTOR:
            {
                if (FlagUtility.HasFlag(_lastEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
                {
                    _lastEntryHeader.Crc              = reader.ReadUInt32();
                    _lastEntryHeader.CompressedSize   = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32();
                    _lastEntryHeader.UncompressedSize = zip64 ? (long)reader.ReadUInt64() : reader.ReadUInt32();
                }
                else
                {
                    reader.ReadBytes(zip64 ? 20 : 12);
                }
                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:
            {
                var entry = new Zip64DirectoryEndHeader();
                entry.Read(reader);
                return(entry);
            }

            case ZIP64_END_OF_CENTRAL_DIRECTORY_LOCATOR:
            {
                var entry = new Zip64DirectoryEndLocatorHeader();
                entry.Read(reader);
                return(entry);
            }

            default:
                return(null);
            }
        }
コード例 #7
0
 internal ZipFilePart(LocalEntryHeader header)
 {
     this.Header = header;
 }