Example #1
0
        /// <summary>
        /// Pushes a new chunk up the stack.
        /// </summary>
        /// <param name="chunk">Must not be null.</param>
        /// <remarks>The <paramref name="chunk"/> is added as a child to the current top chunk.</remarks>
        public void PushChunk(FileChunk chunk)
        {
            Check.IfArgumentNull(chunk, nameof(chunk));

            var parentChunk = CurrentChunk;

            // maintain child-chunks on parent.
            if (parentChunk != null)
            {
                parentChunk.SubChunks.Add(chunk);
            }

            chunkStack.Push(chunk);
        }
        /// <summary>
        /// Skips reading any remaining data for the <paramref name="chunk"/>.
        /// </summary>
        /// <param name="chunk">Must not be null.</param>
        /// <remarks>The underlying file stream is aligned using the <see cref="IStreamNavigator"/> implementation if available.</remarks>
        protected void SkipChunk(FileChunk chunk)
        {
            Check.IfArgumentNull(chunk, nameof(chunk));
            Check.IfArgumentNull(chunk.DataStream, nameof(chunk.DataStream));

            EndStream(chunk.DataStream);

            if (_streamNavigator != null)
            {
                // after skipping the chunk length re-align position of the root stream.
                // sub streams may refuse to move if they are at their end.
                _streamNavigator.AlignPosition(Context.ChunkFile.BaseStream);
            }
        }
Example #3
0
        /// <summary>
        /// Pushes a new chunk up the stack.
        /// </summary>
        /// <param name="chunk">Must not be null.</param>
        /// <remarks>The <paramref name="chunk"/> is added as a child to the current top chunk.</remarks>
        public void PushChunk(FileChunk chunk)
        {
            Contract.Requires(chunk != null);
            Check.IfArgumentNull(chunk, "chunk");

            var parentChunk = this.CurrentChunk;

            // maintain child-chunks on parent.
            if (parentChunk != null)
            {
                parentChunk.SubChunks.Add(chunk);
            }

            this.chunkStack.Push(chunk);
        }
Example #4
0
        protected void SkipChunk(FileChunk chunk)
        {
            Contract.Requires(chunk != null);
            Contract.Requires(chunk.DataStream != null);
            Check.IfArgumentNull(chunk, "chunk");
            Check.IfArgumentNull(chunk.DataStream, "chunk.DataStream");

            this.EndStream(chunk.DataStream);

            if (this.streamNavigator != null)
            {
                // after skipping the chunk length re-align position of the root stream.
                // sub streams may refuse to move if they are at their end.
                this.streamNavigator.AlignPosition(this.context.ChunkFile.BaseStream);
            }
        }
Example #5
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);
        }
        /// <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);
        }
Example #7
0
        /// <summary>
        /// Contract specification.
        /// </summary>
        /// <param name="chunk">Must not be null.</param>
        /// <returns>No Contract.</returns>
        bool IFileChunkHandler.CanRead(FileChunk chunk)
        {
            Contract.Requires(chunk != null);

            throw new System.NotImplementedException();
        }
Example #8
0
        /// <summary>
        /// Indicates if the specified <paramref name="chunk"/> can be read by the handler.
        /// </summary>
        /// <param name="chunk">Must not be null.</param>
        /// <returns>Returns true if the <paramref name="chunk"/> can be read.</returns>
        public override bool CanRead(FileChunk chunk)
        {
            Check.IfArgumentNull(chunk, nameof(chunk));

            return(chunk.DataStream != null && chunk.DataStream.CanRead);
        }