Пример #1
0
        /// <summary>
        /// Reads a four character code.
        /// </summary>
        /// <returns>Returns the code read. Never returns null.</returns>
        public FourCharacterCode ReadFourCharacterCode()
        {
            Contract.Ensures(Contract.Result <FourCharacterCode>() != null);

            var stream = this.CurrentStream;

            return(FourCharacterCode.ReadFrom(stream));
        }
Пример #2
0
        public FileChunk ReadChunkHeader(Stream stream)
        {
            Contract.Requires(stream != null);
            Check.IfArgumentNull(stream, "stream");

            if (this.ValidateStreamPosition(8))
            {
                var chunk = new FileChunk();
                chunk.ChunkId        = FourCharacterCode.ReadFrom(stream);
                chunk.DataLength     = this.numberReader.ReadUInt32AsInt64(stream);
                chunk.ParentPosition = stream.Position;
                chunk.FilePosition   = this.context.ChunkFile.BaseStream.Position;
                chunk.DataStream     = new SubStream(stream, chunk.DataLength);

                return(chunk);
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        /// Reads the first (header) fields of a chunk from the <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">Must not be null.</param>
        /// <returns>Returns null when the stream position does not allow to read the header.</returns>
        /// <remarks>The following properties are set on the returned <see cref="FileChunk"/>.
        /// <see cref="P:FileChunk.ChunkId"/>, <see cref="P:FileChunk.DataLength"/>,
        /// <see cref="P:FileChunk.ParentPosition"/>, <see cref="P:FileChunk.FilePosition"/>
        /// and <see cref="P:FileChunk.DataStream"/>.</remarks>
        public FileChunk ReadChunkHeader(Stream stream)
        {
            Check.IfArgumentNull(stream, nameof(stream));

            if (ValidateStreamPosition(8))
            {
                var chunk = new FileChunk
                {
                    ChunkId        = FourCharacterCode.ReadFrom(stream),
                    DataLength     = _numberReader.ReadUInt32AsInt64(stream),
                    ParentPosition = stream.Position,
                    FilePosition   = Context.ChunkFile.BaseStream.Position
                };
                chunk.DataStream = new SubStream(stream, chunk.DataLength);

                return(chunk);
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// Reads a four character code.
        /// </summary>
        /// <returns>Returns the code read. Never returns null.</returns>
        public FourCharacterCode ReadFourCharacterCode()
        {
            var stream = CurrentStream;

            return(FourCharacterCode.ReadFrom(stream));
        }