Пример #1
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            if (!this.m_Compressed)
            {
                return(this.RawStream.Seek(offset, origin));
            }
            long num = offset;

            if (origin == SeekOrigin.Current)
            {
                num += this.m_Uncomp.Position;
            }
            if (num < 0L)
            {
                throw new Exception("Cannot seek past the begining of the stream.");
            }
            long position = this.m_Uncomp.Position;

            this.m_Uncomp.Seek(0L, SeekOrigin.End);
            while ((origin == SeekOrigin.End || num >= this.m_Uncomp.Length) && this.RawStream.Position < this.RawStream.Length)
            {
                int count1 = this.Raw.ReadInt32();
                int count2 = this.Raw.ReadInt32();
                if (GZBlockIn.m_ReadBuff == null || GZBlockIn.m_ReadBuff.Length < count1)
                {
                    GZBlockIn.m_ReadBuff = new byte[count1];
                }
                if (GZBlockIn.m_CompBuff == null || GZBlockIn.m_CompBuff.Length < count2)
                {
                    GZBlockIn.m_CompBuff = new byte[count2];
                }
                else
                {
                    count2 = GZBlockIn.m_CompBuff.Length;
                }
                this.Raw.Read(GZBlockIn.m_ReadBuff, 0, count1);
                Z_RESULT zResult = ZLib.Decompress(GZBlockIn.m_CompBuff, ref count2, GZBlockIn.m_ReadBuff, count1);
                if (zResult != null)
                {
                    throw new Exception("ZLib error uncompressing: " + ((object)zResult).ToString());
                }
                this.m_Uncomp.Write(GZBlockIn.m_CompBuff, 0, count2);
            }
            this.m_Uncomp.Position = position;
            return(this.m_Uncomp.Seek(offset, origin));
        }
Пример #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (!this.m_Compressed)
            {
                return(this.RawStream.Read(buffer, offset, count));
            }
            long position = this.m_Uncomp.Position;

            this.m_Uncomp.Seek(0L, SeekOrigin.End);
            while (position + (long)count > this.m_Uncomp.Length && this.RawStream.Position + 8L < this.RawStream.Length)
            {
                int count1 = this.Raw.ReadInt32();
                int count2 = this.Raw.ReadInt32();
                if (count1 <= 268435456 && count1 > 0 && (count2 <= 268435456 && count2 > 0) && this.RawStream.Position + (long)count1 <= this.RawStream.Length)
                {
                    if (GZBlockIn.m_ReadBuff == null || GZBlockIn.m_ReadBuff.Length < count1)
                    {
                        GZBlockIn.m_ReadBuff = new byte[count1];
                    }
                    if (GZBlockIn.m_CompBuff == null || GZBlockIn.m_CompBuff.Length < count2)
                    {
                        GZBlockIn.m_CompBuff = new byte[count2];
                    }
                    else
                    {
                        count2 = GZBlockIn.m_CompBuff.Length;
                    }
                    this.Raw.Read(GZBlockIn.m_ReadBuff, 0, count1);
                    Z_RESULT zResult = ZLib.Decompress(GZBlockIn.m_CompBuff, ref count2, GZBlockIn.m_ReadBuff, count1);
                    if (zResult != null)
                    {
                        throw new Exception("ZLib error uncompressing: " + ((object)zResult).ToString());
                    }
                    this.m_Uncomp.Write(GZBlockIn.m_CompBuff, 0, count2);
                }
                else
                {
                    break;
                }
            }
            this.m_Uncomp.Position = position;
            return(this.m_Uncomp.Read(buffer, offset, count));
        }