Ejemplo n.º 1
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (this.crc != null)
     {
         this.crc.SlurpBlock(buffer, offset, count);
     }
     if (this._streamMode == ZlibBaseStream.StreamMode.Undefined)
     {
         this._streamMode = ZlibBaseStream.StreamMode.Writer;
     }
     else if (this._streamMode != ZlibBaseStream.StreamMode.Writer)
     {
         throw new ZlibException("Cannot Write after Reading.");
     }
     if (count == 0)
     {
         return;
     }
     this.z.InputBuffer = buffer;
     this._z.Reset();
     this._z.NextIn           = offset;
     this._z.AvailableBytesIn = count;
     while (true)
     {
         this._z.OutputBuffer      = this.workingBuffer;
         this._z.NextOut           = 0;
         this._z.AvailableBytesOut = this._workingBuffer.Length;
         int num = this._wantCompress ? this._z.Deflate(this._flushMode) : this._z.Inflate(this._flushMode);
         if (num != 0 && num != 1)
         {
             break;
         }
         this._stream.Write(this._workingBuffer, 0, this._workingBuffer.Length - this._z.AvailableBytesOut);
         bool flag = this._z.AvailableBytesIn == 0 && this._z.AvailableBytesOut != 0;
         if (this._flavor == ZlibStreamFlavor.GZIP && !this._wantCompress)
         {
             flag = (this._z.AvailableBytesIn == 8 && this._z.AvailableBytesOut != 0);
         }
         if (flag)
         {
             return;
         }
     }
     throw new ZlibException((this._wantCompress ? "de" : "in") + "flating: " + this._z.Message);
 }
Ejemplo n.º 2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (this._streamMode == ZlibBaseStream.StreamMode.Undefined)
            {
                if (!this._stream.CanRead)
                {
                    throw new ZlibException("The stream is not readable.");
                }
                this._streamMode        = ZlibBaseStream.StreamMode.Reader;
                this.z.AvailableBytesIn = 0;
                if (this._flavor == ZlibStreamFlavor.GZIP)
                {
                    this._gzipHeaderByteCount = this._ReadAndValidateGzipHeader();
                    if (this._gzipHeaderByteCount == 0)
                    {
                        return(0);
                    }
                }
            }
            if (this._streamMode != ZlibBaseStream.StreamMode.Reader)
            {
                throw new ZlibException("Cannot Read after Writing.");
            }
            if (count == 0)
            {
                return(0);
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (offset < buffer.GetLowerBound(0))
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (offset + count > buffer.GetLength(0))
            {
                throw new ArgumentOutOfRangeException("count");
            }
            this._z.OutputBuffer      = buffer;
            this._z.NextOut           = offset;
            this._z.AvailableBytesOut = count;
            this._z.InputBuffer       = this.workingBuffer;
            int num;

            do
            {
                if (this._z.AvailableBytesIn == 0 && !this.nomoreinput)
                {
                    this._z.NextIn           = 0;
                    this._z.AvailableBytesIn = this._stream.Read(this._workingBuffer, 0, this._workingBuffer.Length);
                    if (this._z.AvailableBytesIn == 0)
                    {
                        this.nomoreinput = true;
                    }
                }
                num = this._z.Inflate(this._flushMode);
                if (this.nomoreinput && num == -5)
                {
                    return(0);
                }
                if (num != 0 && num != 1)
                {
                    throw new ZlibException(string.Format("inflating:  rc={0}  msg={1}", (object)num, (object)this._z.Message));
                }
            }while ((!this.nomoreinput && num != 1 || this._z.AvailableBytesOut != count) && (this._z.AvailableBytesOut > 0 && !this.nomoreinput && num == 0));
            if (this._z.AvailableBytesOut > 0)
            {
                if (num != 0 || this._z.AvailableBytesIn != 0)
                {
                }
                if (!this.nomoreinput)
                {
                }
            }
            int count1 = count - this._z.AvailableBytesOut;

            if (this.crc != null)
            {
                this.crc.SlurpBlock(buffer, offset, count1);
            }
            return(count1);
        }
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (this.crc != null)
         this.crc.SlurpBlock(buffer, offset, count);
     if (this._streamMode == ZlibBaseStream.StreamMode.Undefined)
         this._streamMode = ZlibBaseStream.StreamMode.Writer;
     else if (this._streamMode != ZlibBaseStream.StreamMode.Writer)
         throw new ZlibException("Cannot Write after Reading.");
     if (count == 0)
         return;
     this.z.InputBuffer = buffer;
     this._z.NextIn = offset;
     this._z.AvailableBytesIn = count;
     bool flag;
     do
     {
         this._z.OutputBuffer = this.workingBuffer;
         this._z.NextOut = 0;
         this._z.AvailableBytesOut = this._workingBuffer.Length;
         int num = this._z.Inflate(this._flushMode);
         if (num != 0 && num != 1)
             throw new ZlibException("inflating: " + this._z.Message);
         this._stream.Write(this._workingBuffer, 0, this._workingBuffer.Length - this._z.AvailableBytesOut);
         flag = this._z.AvailableBytesIn == 0 && this._z.AvailableBytesOut != 0;
         if (this._flavor == ZlibStreamFlavor.GZIP)
             flag = this._z.AvailableBytesIn == 8 && this._z.AvailableBytesOut != 0;
     }
     while (!flag);
 }
 public override int Read(byte[] buffer, int offset, int count)
 {
     if (this._streamMode == ZlibBaseStream.StreamMode.Undefined)
     {
         if (!this._stream.CanRead)
             throw new ZlibException("The stream is not readable.");
         this._streamMode = ZlibBaseStream.StreamMode.Reader;
         this.z.AvailableBytesIn = 0;
         if (this._flavor == ZlibStreamFlavor.GZIP)
         {
             this._gzipHeaderByteCount = this._ReadAndValidateGzipHeader();
             if (this._gzipHeaderByteCount == 0)
                 return 0;
         }
     }
     if (this._streamMode != ZlibBaseStream.StreamMode.Reader)
         throw new ZlibException("Cannot Read after Writing.");
     if (count == 0)
         return 0;
     if (buffer == null)
         throw new ArgumentNullException("buffer");
     if (count < 0)
         throw new ArgumentOutOfRangeException("count");
     if (offset < buffer.GetLowerBound(0))
         throw new ArgumentOutOfRangeException("offset");
     if (offset + count > buffer.GetLength(0))
         throw new ArgumentOutOfRangeException("count");
     this._z.OutputBuffer = buffer;
     this._z.NextOut = offset;
     this._z.AvailableBytesOut = count;
     this._z.InputBuffer = this.workingBuffer;
     int num;
     do
     {
         if (this._z.AvailableBytesIn == 0 && !this.nomoreinput)
         {
             this._z.NextIn = 0;
             this._z.AvailableBytesIn = this._stream.Read(this._workingBuffer, 0, this._workingBuffer.Length);
             if (this._z.AvailableBytesIn == 0)
                 this.nomoreinput = true;
         }
         num = this._z.Inflate(this._flushMode);
         if (this.nomoreinput && num == -5)
             return 0;
         if (num != 0 && num != 1)
             throw new ZlibException(string.Format("inflating:  rc={0}  msg={1}", (object)num, (object)this._z.Message));
     }
     while ((!this.nomoreinput && num != 1 || this._z.AvailableBytesOut != count) && (this._z.AvailableBytesOut > 0 && !this.nomoreinput && num == 0));
     if (this._z.AvailableBytesOut > 0)
     {
         if (num != 0 || this._z.AvailableBytesIn != 0)
         {}
         if (!this.nomoreinput)
         {}
     }
     int count1 = count - this._z.AvailableBytesOut;
     if (this.crc != null)
         this.crc.SlurpBlock(buffer, offset, count1);
     return count1;
 }
Ejemplo n.º 5
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (this._streamMode == ZlibBaseStream.StreamMode.Undefined)
            {
                if (!this._stream.CanRead)
                {
                    throw new ZlibException("The stream is not readable.");
                }
                this._streamMode        = ZlibBaseStream.StreamMode.Reader;
                this.z.AvailableBytesIn = 0;
                if (this._flavor == ZlibStreamFlavor.GZIP)
                {
                    this._gzipHeaderByteCount = this._ReadAndValidateGzipHeader();
                    if (this._gzipHeaderByteCount == 0)
                    {
                        return(0);
                    }
                }
            }
            if (this._streamMode != ZlibBaseStream.StreamMode.Reader)
            {
                throw new ZlibException("Cannot Read after Writing.");
            }
            if (count == 0)
            {
                return(0);
            }
            if (this.nomoreinput && this._wantCompress)
            {
                return(0);
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (offset < buffer.GetLowerBound(0))
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (offset + count > buffer.GetLength(0))
            {
                throw new ArgumentOutOfRangeException("count");
            }
            this._z.OutputBuffer      = buffer;
            this._z.NextOut           = offset;
            this._z.AvailableBytesOut = count;
            this._z.InputBuffer       = this.workingBuffer;
            int num;

            while (true)
            {
                if (this._z.AvailableBytesIn == 0 && !this.nomoreinput)
                {
                    this._z.NextIn           = 0;
                    this._z.AvailableBytesIn = this._stream.Read(this._workingBuffer, 0, this._workingBuffer.Length);
                    if (this._z.AvailableBytesIn == 0)
                    {
                        this.nomoreinput = true;
                    }
                }
                num = ((!this._wantCompress) ? this._z.Inflate(this._flushMode) : this._z.Deflate(this._flushMode));
                if (this.nomoreinput && num == -5)
                {
                    break;
                }
                if (num != 0 && num != 1)
                {
                    goto Block_20;
                }
                if ((this.nomoreinput || num == 1) && this._z.AvailableBytesOut == count)
                {
                    goto Block_23;
                }
                if (this._z.AvailableBytesOut <= 0 || this.nomoreinput || num != 0)
                {
                    goto IL_263;
                }
            }
            return(0);

Block_20:
            throw new ZlibException(string.Format("{0}flating:  rc={1}  msg={2}", (!this._wantCompress) ? "in" : "de", num, this._z.Message));
Block_23:
IL_263:
            if (this._z.AvailableBytesOut > 0)
            {
                if (num != 0 || this._z.AvailableBytesIn == 0)
                {
                }
                if (this.nomoreinput && this._wantCompress)
                {
                    num = this._z.Deflate(FlushType.Finish);
                    if (num != 0 && num != 1)
                    {
                        throw new ZlibException(string.Format("Deflating:  rc={0}  msg={1}", num, this._z.Message));
                    }
                }
            }
            num = count - this._z.AvailableBytesOut;
            if (this.crc != null)
            {
                this.crc.SlurpBlock(buffer, offset, num);
            }
            return(num);
        }