コード例 #1
0
ファイル: PkgArchive.cs プロジェクト: gdtiti/qq-game-resource
        /// <summary>
        /// Opens the entry from the archive.
        /// </summary>
        /// <returns>A stream to read the contents of the entry from.</returns>
        /// <remarks>The <code>PkgArchive</code> object must not be disposed
        /// in order to access this stream.</remarks>
        /// <exception cref="InvalidDataException">The file format is not 
        /// supported.</exception>
        /// <exception cref="IOException">An IO error occurred.</exception>
        /// <exception cref="ObjectDisposedException">The containing archive 
        /// is disposed.</exception>
        public Stream Open()
        {
            // Obtain the underlying stream of the archive.
            Stream stream = archive.Stream;

            // Validate the content range specified in the index entry.
            if (info.ContentOffset < 0)
                throw new InvalidDataException("ContentOffset must be greater than or equal to 0.");
            if (info.ContentOffset >= stream.Length)
                throw new InvalidDataException("ContentOffset must not point beyond EOF.");
            if (info.ContentSize < 6)
                throw new InvalidDataException("ContentSize must be greater than or equal to 6.");
            if (info.ContentSize > stream.Length - info.ContentOffset)
                throw new InvalidDataException("ContentSize must not exceed the remaining stream length.");

            // Create a stream view to restrict stream access to the range
            // specified in the index entry.
            stream.Seek(info.ContentOffset, SeekOrigin.Begin);
            //Util.IO.StreamView streamView = new Util.IO.StreamView(
            //    stream, info.ContentOffset, info.ContentSize);
            LimitedLengthStream streamView = new LimitedLengthStream(stream, info.ContentSize, true);

            // Create and return a ZLibStream from here.
            return new ZLibStream(streamView, CompressionMode.Decompress);
        }
コード例 #2
0
ファイル: MifImage.cs プロジェクト: gdtiti/qq-game-resource
        /// <summary>
        /// Reads delta-encoded data from the underlying stream into the 
        /// specified buffer.
        /// </summary>
        private void ReadDeltaEncodedPixelData(byte[] buffer)
        {
            // Read input size.
            int inputSize = ReadInt32();
            if (inputSize < 0)
                throw new InvalidDataException("InputSize must be greater than or equal to zero.");

            // Create a stream view to cover the range.
            using (LimitedLengthStream view = new LimitedLengthStream(
                   this.BaseStream, inputSize, true))
            using (BinaryReader reader = new BinaryReader(view))
            {
                MifDeltaEncoding.Decode(buffer, reader);
            }
        }