コード例 #1
0
 private void FillBase(RarHeader baseHeader)
 {
     HeadCRC        = baseHeader.HeadCRC;
     HeaderType     = baseHeader.HeaderType;
     Flags          = baseHeader.Flags;
     HeaderSize     = baseHeader.HeaderSize;
     AdditionalSize = baseHeader.AdditionalSize;
     ReadBytes      = baseHeader.ReadBytes;
 }
コード例 #2
0
        internal static RarHeader Create(MarkingBinaryReader reader)
        {
            try
            {
                RarHeader header = new RarHeader();

                reader.Mark();
                header.ReadFromReader(reader);
                header.ReadBytes += reader.CurrentReadByteCount;

                return(header);
            }
            catch (EndOfStreamException)
            {
                return(null);
            }
        }
コード例 #3
0
        private RarHeader ReadNextHeader(Stream stream)
        {
            MarkingBinaryReader reader = new MarkingBinaryReader(stream);
            RarHeader           header = RarHeader.Create(reader);

            if (header == null)
            {
                return(null);
            }
            switch (header.HeaderType)
            {
            case HeaderType.ArchiveHeader:
            {
                return(header.PromoteHeader <ArchiveHeader>(reader));
            }

            case HeaderType.MarkHeader:
            {
                return(header.PromoteHeader <MarkHeader>(reader));
            }

            case HeaderType.NewSubHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    //skip the data because it's useless?
                    reader.BaseStream.Skip(fh.CompressedSize);
                }
                break;

                default:
                {
                    throw new InvalidRarFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.FileHeader:
            {
                FileHeader fh = header.PromoteHeader <FileHeader>(reader);
                switch (StreamingMode)
                {
                case StreamingMode.Seekable:
                {
                    fh.DataStartPosition        = reader.BaseStream.Position;
                    reader.BaseStream.Position += fh.CompressedSize;
                }
                break;

                case StreamingMode.Streaming:
                {
                    ReadOnlySubStream ms
                                    = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
                    fh.PackedStream = ms;
                }
                break;

                default:
                {
                    throw new InvalidRarFormatException("Invalid StreamingMode");
                }
                }
                return(fh);
            }

            case HeaderType.EndArchiveHeader:
            {
                return(header.PromoteHeader <EndArchiveHeader>(reader));
            }

            default:
            {
                throw new InvalidRarFormatException("Invalid Rar Header: " + header.HeaderType.ToString());
            }
            }
        }