Exemple #1
0
        internal int SetDictionary(byte[] dictionary)
        {
            int num         = dictionary.Length;
            int sourceIndex = 0;

            if (dictionary == null || this.status != DeflateManager.INIT_STATE)
            {
                throw new ZlibException("Stream error.");
            }
            this._codec._Adler32 = Adler.Adler32(this._codec._Adler32, dictionary, 0, dictionary.Length);
            if (num < DeflateManager.MIN_MATCH)
            {
                return(0);
            }
            if (num > this.w_size - DeflateManager.MIN_LOOKAHEAD)
            {
                num         = this.w_size - DeflateManager.MIN_LOOKAHEAD;
                sourceIndex = dictionary.Length - num;
            }
            Array.Copy(dictionary, sourceIndex, this.window, 0, num);
            this.strstart    = num;
            this.block_start = num;
            this.ins_h       = (int)(this.window[0] & 255);
            this.ins_h       = ((this.ins_h << this.hash_shift ^ (int)(this.window[1] & 255)) & this.hash_mask);
            for (int i = 0; i <= num - DeflateManager.MIN_MATCH; i++)
            {
                this.ins_h = ((this.ins_h << this.hash_shift ^ (int)(this.window[i + (DeflateManager.MIN_MATCH - 1)] & 255)) & this.hash_mask);
                this.prev[i & this.w_mask] = this.head[this.ins_h];
                this.head[this.ins_h]      = (short)i;
            }
            return(0);
        }
Exemple #2
0
        internal int SetDictionary(byte[] dictionary)
        {
            int length      = dictionary.Length;
            int sourceIndex = 0;

            if ((dictionary == null) || (this.status != INIT_STATE))
            {
                throw new ZlibException("Stream error.");
            }
            this._codec._Adler32 = Adler.Adler32(this._codec._Adler32, dictionary, 0, dictionary.Length);
            if (length >= MIN_MATCH)
            {
                if (length > (this.w_size - MIN_LOOKAHEAD))
                {
                    length      = this.w_size - MIN_LOOKAHEAD;
                    sourceIndex = dictionary.Length - length;
                }
                Array.Copy(dictionary, sourceIndex, this.window, 0, length);
                this.strstart    = length;
                this.block_start = length;
                this.ins_h       = this.window[0] & 0xff;
                this.ins_h       = ((this.ins_h << this.hash_shift) ^ (this.window[1] & 0xff)) & this.hash_mask;
                for (int i = 0; i <= (length - MIN_MATCH); i++)
                {
                    this.ins_h = ((this.ins_h << this.hash_shift) ^ (this.window[i + (MIN_MATCH - 1)] & 0xff)) & this.hash_mask;
                    this.prev[i & this.w_mask] = this.head[this.ins_h];
                    this.head[this.ins_h]      = (short)i;
                }
            }
            return(0);
        }
        internal int SetDictionary(byte[] dictionary)
        {
            int num         = dictionary.Length;
            int sourceIndex = 0;

            if (dictionary == null || status != INIT_STATE)
            {
                throw new ZlibException("Stream error.");
            }
            _codec._Adler32 = Adler.Adler32(_codec._Adler32, dictionary, 0, dictionary.Length);
            if (num < MIN_MATCH)
            {
                return(0);
            }
            if (num > w_size - MIN_LOOKAHEAD)
            {
                num         = w_size - MIN_LOOKAHEAD;
                sourceIndex = dictionary.Length - num;
            }
            Array.Copy(dictionary, sourceIndex, window, 0, num);
            strstart    = num;
            block_start = num;
            ins_h       = (window[0] & 0xFF);
            ins_h       = (((ins_h << hash_shift) ^ (window[1] & 0xFF)) & hash_mask);
            for (int i = 0; i <= num - MIN_MATCH; i++)
            {
                ins_h            = (((ins_h << hash_shift) ^ (window[i + (MIN_MATCH - 1)] & 0xFF)) & hash_mask);
                prev[i & w_mask] = head[ins_h];
                head[ins_h]      = (short)i;
            }
            return(0);
        }
 internal int Flush(int r)
 {
     for (int i = 0; i < 2; i++)
     {
         int availableBytesOut;
         if (i == 0)
         {
             availableBytesOut = ((this.readAt > this.writeAt) ? this.end : this.writeAt) - this.readAt;
         }
         else
         {
             availableBytesOut = this.writeAt - this.readAt;
         }
         if (availableBytesOut == 0)
         {
             if (r == -5)
             {
                 r = 0;
             }
             return(r);
         }
         if (availableBytesOut > this._codec.AvailableBytesOut)
         {
             availableBytesOut = this._codec.AvailableBytesOut;
         }
         if ((availableBytesOut != 0) && (r == -5))
         {
             r = 0;
         }
         this._codec.AvailableBytesOut -= availableBytesOut;
         this._codec.TotalBytesOut     += availableBytesOut;
         if (this.checkfn != null)
         {
             this._codec._Adler32 = this.check = Adler.Adler32(this.check, this.window, this.readAt, availableBytesOut);
         }
         Array.Copy(this.window, this.readAt, this._codec.OutputBuffer, this._codec.NextOut, availableBytesOut);
         this._codec.NextOut += availableBytesOut;
         this.readAt         += availableBytesOut;
         if ((this.readAt == this.end) && (i == 0))
         {
             this.readAt = 0;
             if (this.writeAt == this.end)
             {
                 this.writeAt = 0;
             }
         }
         else
         {
             i++;
         }
     }
     return(r);
 }
Exemple #5
0
 internal int Flush(int r)
 {
     for (int i = 0; i < 2; i++)
     {
         int num;
         if (i == 0)
         {
             num = ((this.readAt > this.writeAt) ? this.end : this.writeAt) - this.readAt;
         }
         else
         {
             num = this.writeAt - this.readAt;
         }
         if (num == 0)
         {
             if (r == -5)
             {
                 r = 0;
             }
             return(r);
         }
         if (num > this._codec.AvailableBytesOut)
         {
             num = this._codec.AvailableBytesOut;
         }
         if (num != 0 && r == -5)
         {
             r = 0;
         }
         this._codec.AvailableBytesOut -= num;
         this._codec.TotalBytesOut     += (long)num;
         if (this.checkfn != null)
         {
             this._codec._Adler32 = (this.check = Adler.Adler32(this.check, this.window, this.readAt, num));
         }
         Array.Copy(this.window, this.readAt, this._codec.OutputBuffer, this._codec.NextOut, num);
         this._codec.NextOut += num;
         this.readAt         += num;
         if (this.readAt == this.end && i == 0)
         {
             this.readAt = 0;
             if (this.writeAt == this.end)
             {
                 this.writeAt = 0;
             }
         }
         else
         {
             i++;
         }
     }
     return(r);
 }
 internal void Reset()
 {
     _codec.TotalBytesIn = (_codec.TotalBytesOut = 0L);
     _codec.Message      = null;
     pendingCount        = 0;
     nextPending         = 0;
     Rfc1950BytesEmitted = false;
     status          = ((!WantRfc1950HeaderBytes) ? BUSY_STATE : INIT_STATE);
     _codec._Adler32 = Adler.Adler32(0u, null, 0, 0);
     last_flush      = 0;
     _InitializeTreeData();
     _InitializeLazyMatch();
 }
Exemple #7
0
 internal void Reset()
 {
     this._codec.TotalBytesIn = (this._codec.TotalBytesOut = 0L);
     this._codec.Message      = null;
     this.pendingCount        = 0;
     this.nextPending         = 0;
     this.Rfc1950BytesEmitted = false;
     this.status          = ((!this.WantRfc1950HeaderBytes) ? DeflateManager.BUSY_STATE : DeflateManager.INIT_STATE);
     this._codec._Adler32 = Adler.Adler32(0u, null, 0, 0);
     this.last_flush      = 0;
     this._InitializeTreeData();
     this._InitializeLazyMatch();
 }
Exemple #8
0
        internal uint Reset()
        {
            uint result = check;

            mode   = InflateBlockMode.TYPE;
            bitk   = 0;
            bitb   = 0;
            readAt = (writeAt = 0);
            if (checkfn != null)
            {
                _codec._Adler32 = (check = Adler.Adler32(0u, null, 0, 0));
            }
            return(result);
        }
Exemple #9
0
        internal uint Reset()
        {
            uint result = this.check;

            this.mode   = InflateBlocks.InflateBlockMode.TYPE;
            this.bitk   = 0;
            this.bitb   = 0;
            this.readAt = (this.writeAt = 0);
            if (this.checkfn != null)
            {
                this._codec._Adler32 = (this.check = Adler.Adler32(0u, null, 0, 0));
            }
            return(result);
        }
        internal uint Reset()
        {
            uint check = this.check;

            this.mode   = InflateBlockMode.TYPE;
            this.bitk   = 0;
            this.bitb   = 0;
            this.readAt = this.writeAt = 0;
            if (this.checkfn != null)
            {
                this._codec._Adler32 = this.check = Adler.Adler32(0, null, 0, 0);
            }
            return(check);
        }
Exemple #11
0
 internal int Flush(int r)
 {
     for (int i = 0; i < 2; i++)
     {
         int num = (i != 0) ? (writeAt - readAt) : (((readAt > writeAt) ? end : writeAt) - readAt);
         if (num == 0)
         {
             if (r == -5)
             {
                 r = 0;
             }
             return(r);
         }
         if (num > _codec.AvailableBytesOut)
         {
             num = _codec.AvailableBytesOut;
         }
         if (num != 0 && r == -5)
         {
             r = 0;
         }
         _codec.AvailableBytesOut -= num;
         _codec.TotalBytesOut     += num;
         if (checkfn != null)
         {
             _codec._Adler32 = (check = Adler.Adler32(check, window, readAt, num));
         }
         Array.Copy(window, readAt, _codec.OutputBuffer, _codec.NextOut, num);
         _codec.NextOut += num;
         readAt         += num;
         if (readAt == end && i == 0)
         {
             readAt = 0;
             if (writeAt == end)
             {
                 writeAt = 0;
             }
         }
         else
         {
             i++;
         }
     }
     return(r);
 }
		internal int read_buf(byte[] buf, int start, int size)
		{
			int num = AvailableBytesIn;
			if (num > size)
			{
				num = size;
			}
			if (num == 0)
			{
				return 0;
			}
			AvailableBytesIn -= num;
			if (dstate.WantRfc1950HeaderBytes)
			{
				_Adler32 = Adler.Adler32(_Adler32, InputBuffer, NextIn, num);
			}
			Array.Copy(InputBuffer, NextIn, buf, start, num);
			NextIn += num;
			TotalBytesIn += num;
			return num;
		}
        internal int read_buf(byte[] buf, int start, int size)
        {
            int availableBytesIn = this.AvailableBytesIn;

            if (availableBytesIn > size)
            {
                availableBytesIn = size;
            }
            if (availableBytesIn == 0)
            {
                return(0);
            }
            this.AvailableBytesIn -= availableBytesIn;
            if (this.dstate.WantRfc1950HeaderBytes)
            {
                this._Adler32 = Adler.Adler32(this._Adler32, this.InputBuffer, this.NextIn, availableBytesIn);
            }
            Array.Copy(this.InputBuffer, this.NextIn, buf, start, availableBytesIn);
            this.NextIn       += availableBytesIn;
            this.TotalBytesIn += availableBytesIn;
            return(availableBytesIn);
        }
Exemple #14
0
        internal int read_buf(byte[] buf, int start, int size)
        {
            int num = this.AvailableBytesIn;

            if (num > size)
            {
                num = size;
            }
            if (num == 0)
            {
                return(0);
            }
            this.AvailableBytesIn -= num;
            if (this.dstate.WantRfc1950HeaderBytes)
            {
                this._Adler32 = Adler.Adler32(this._Adler32, this.InputBuffer, this.NextIn, num);
            }
            Array.Copy(this.InputBuffer, this.NextIn, buf, start, num);
            this.NextIn       += num;
            this.TotalBytesIn += (long)num;
            return(num);
        }
        internal int SetDictionary(byte[] dictionary)
        {
            int start  = 0;
            int length = dictionary.Length;

            if (this.mode != InflateManagerMode.DICT0)
            {
                throw new ZlibException("Stream error.");
            }
            if (Adler.Adler32(1, dictionary, 0, dictionary.Length) != this._codec._Adler32)
            {
                return(-3);
            }
            this._codec._Adler32 = Adler.Adler32(0, null, 0, 0);
            if (length >= (((int)1) << this.wbits))
            {
                length = (((int)1) << this.wbits) - 1;
                start  = dictionary.Length - length;
            }
            this.blocks.SetDictionary(dictionary, start, length);
            this.mode = InflateManagerMode.BLOCKS;
            return(0);
        }
Exemple #16
0
        internal int SetDictionary(byte[] dictionary)
        {
            int start = 0;
            int num   = dictionary.Length;

            if (this.mode != InflateManager.InflateManagerMode.DICT0)
            {
                throw new ZlibException("Stream error.");
            }
            if (Adler.Adler32(1u, dictionary, 0, dictionary.Length) != this._codec._Adler32)
            {
                return(-3);
            }
            this._codec._Adler32 = Adler.Adler32(0u, null, 0, 0);
            if (num >= 1 << this.wbits)
            {
                num   = (1 << this.wbits) - 1;
                start = dictionary.Length - num;
            }
            this.blocks.SetDictionary(dictionary, start, num);
            this.mode = InflateManager.InflateManagerMode.BLOCKS;
            return(0);
        }
Exemple #17
0
        // Read a new buffer from the current input stream, update the adler32
        // and total number of bytes read.  All deflate() input goes through
        // this function so some applications may wish to modify it to avoid
        // allocating a large strm->next_in buffer and copying from it.
        // (See also flush_pending()).
        internal int read_buf(byte[] buf, int start, int size)
        {
            int len = AvailableBytesIn;

            if (len > size)
            {
                len = size;
            }
            if (len == 0)
            {
                return(0);
            }

            AvailableBytesIn -= len;

            if (dstate.WantRfc1950HeaderBytes)
            {
                _Adler32 = Adler.Adler32(_Adler32, InputBuffer, NextIn, len);
            }
            Array.Copy(InputBuffer, NextIn, buf, start, len);
            NextIn       += len;
            TotalBytesIn += len;
            return(len);
        }
Exemple #18
0
        internal int Deflate(FlushType flush)
        {
            if (this._codec.OutputBuffer == null || (this._codec.InputBuffer == null && this._codec.AvailableBytesIn != 0) || (this.status == DeflateManager.FINISH_STATE && flush != FlushType.Finish))
            {
                this._codec.Message = DeflateManager._ErrorMessage[4];
                throw new ZlibException(string.Format("Something is fishy. [{0}]", this._codec.Message));
            }
            if (this._codec.AvailableBytesOut == 0)
            {
                this._codec.Message = DeflateManager._ErrorMessage[7];
                throw new ZlibException("OutputBuffer is full (AvailableBytesOut == 0)");
            }
            int num = this.last_flush;

            this.last_flush = (int)flush;
            if (this.status == DeflateManager.INIT_STATE)
            {
                int num2 = DeflateManager.Z_DEFLATED + (this.w_bits - 8 << 4) << 8;
                int num3 = (this.compressionLevel - CompressionLevel.BestSpeed & 255) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                num2 |= num3 << 6;
                if (this.strstart != 0)
                {
                    num2 |= DeflateManager.PRESET_DICT;
                }
                num2       += 31 - num2 % 31;
                this.status = DeflateManager.BUSY_STATE;
                this.pending[this.pendingCount++] = (byte)(num2 >> 8);
                this.pending[this.pendingCount++] = (byte)num2;
                if (this.strstart != 0)
                {
                    this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 4278190080u) >> 24);
                    this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 16711680u) >> 16);
                    this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 65280u) >> 8);
                    this.pending[this.pendingCount++] = (byte)(this._codec._Adler32 & 255u);
                }
                this._codec._Adler32 = Adler.Adler32(0u, null, 0, 0);
            }
            if (this.pendingCount != 0)
            {
                this._codec.flush_pending();
                if (this._codec.AvailableBytesOut == 0)
                {
                    this.last_flush = -1;
                    return(0);
                }
            }
            else if (this._codec.AvailableBytesIn == 0 && flush <= (FlushType)num && flush != FlushType.Finish)
            {
                return(0);
            }
            if (this.status == DeflateManager.FINISH_STATE && this._codec.AvailableBytesIn != 0)
            {
                this._codec.Message = DeflateManager._ErrorMessage[7];
                throw new ZlibException("status == FINISH_STATE && _codec.AvailableBytesIn != 0");
            }
            if (this._codec.AvailableBytesIn != 0 || this.lookahead != 0 || (flush != FlushType.None && this.status != DeflateManager.FINISH_STATE))
            {
                BlockState blockState = this.DeflateFunction(flush);
                if (blockState == BlockState.FinishStarted || blockState == BlockState.FinishDone)
                {
                    this.status = DeflateManager.FINISH_STATE;
                }
                if (blockState == BlockState.NeedMore || blockState == BlockState.FinishStarted)
                {
                    if (this._codec.AvailableBytesOut == 0)
                    {
                        this.last_flush = -1;
                    }
                    return(0);
                }
                if (blockState == BlockState.BlockDone)
                {
                    if (flush == FlushType.Partial)
                    {
                        this._tr_align();
                    }
                    else
                    {
                        this._tr_stored_block(0, 0, false);
                        if (flush == FlushType.Full)
                        {
                            for (int i = 0; i < this.hash_size; i++)
                            {
                                this.head[i] = 0;
                            }
                        }
                    }
                    this._codec.flush_pending();
                    if (this._codec.AvailableBytesOut == 0)
                    {
                        this.last_flush = -1;
                        return(0);
                    }
                }
            }
            if (flush != FlushType.Finish)
            {
                return(0);
            }
            if (!this.WantRfc1950HeaderBytes || this.Rfc1950BytesEmitted)
            {
                return(1);
            }
            this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 4278190080u) >> 24);
            this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 16711680u) >> 16);
            this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 65280u) >> 8);
            this.pending[this.pendingCount++] = (byte)(this._codec._Adler32 & 255u);
            this._codec.flush_pending();
            this.Rfc1950BytesEmitted = true;
            return((this.pendingCount == 0) ? 1 : 0);
        }
Exemple #19
0
        internal int Deflate(FlushType flush)
        {
            if (((this._codec.OutputBuffer == null) || ((this._codec.InputBuffer == null) && (this._codec.AvailableBytesIn != 0))) || ((this.status == FINISH_STATE) && (flush != FlushType.Finish)))
            {
                this._codec.Message = _ErrorMessage[4];
                throw new ZlibException($"Something is fishy. [{this._codec.Message}]");
            }
            if (this._codec.AvailableBytesOut == 0)
            {
                this._codec.Message = _ErrorMessage[7];
                throw new ZlibException("OutputBuffer is full (AvailableBytesOut == 0)");
            }
            int num = this.last_flush;

            this.last_flush = (int)flush;
            if (this.status == INIT_STATE)
            {
                int num2 = (Z_DEFLATED + ((this.w_bits - 8) << 4)) << 8;
                int num3 = ((int)((this.compressionLevel - 1) & 0xff)) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                num2 |= num3 << 6;
                if (this.strstart != 0)
                {
                    num2 |= PRESET_DICT;
                }
                num2       += 0x1f - (num2 % 0x1f);
                this.status = BUSY_STATE;
                this.pending[this.pendingCount++] = (byte)(num2 >> 8);
                this.pending[this.pendingCount++] = (byte)num2;
                if (this.strstart != 0)
                {
                    this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & -16777216) >> 0x18);
                    this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 0xff0000) >> 0x10);
                    this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 0xff00) >> 8);
                    this.pending[this.pendingCount++] = (byte)(this._codec._Adler32 & 0xff);
                }
                this._codec._Adler32 = Adler.Adler32(0, null, 0, 0);
            }
            if (this.pendingCount != 0)
            {
                this._codec.flush_pending();
                if (this._codec.AvailableBytesOut == 0)
                {
                    this.last_flush = -1;
                    return(0);
                }
            }
            else if (((this._codec.AvailableBytesIn == 0) && (flush <= num)) && (flush != FlushType.Finish))
            {
                return(0);
            }
            if ((this.status == FINISH_STATE) && (this._codec.AvailableBytesIn != 0))
            {
                this._codec.Message = _ErrorMessage[7];
                throw new ZlibException("status == FINISH_STATE && _codec.AvailableBytesIn != 0");
            }
            if (((this._codec.AvailableBytesIn != 0) || (this.lookahead != 0)) || ((flush != FlushType.None) && (this.status != FINISH_STATE)))
            {
                BlockState state = this.DeflateFunction(flush);
                switch (state)
                {
                case BlockState.FinishStarted:
                case BlockState.FinishDone:
                    this.status = FINISH_STATE;
                    break;
                }
                if ((state == BlockState.NeedMore) || (state == BlockState.FinishStarted))
                {
                    if (this._codec.AvailableBytesOut == 0)
                    {
                        this.last_flush = -1;
                    }
                    return(0);
                }
                if (state == BlockState.BlockDone)
                {
                    if (flush == FlushType.Partial)
                    {
                        this._tr_align();
                    }
                    else
                    {
                        this._tr_stored_block(0, 0, false);
                        if (flush == FlushType.Full)
                        {
                            for (int i = 0; i < this.hash_size; i++)
                            {
                                this.head[i] = 0;
                            }
                        }
                    }
                    this._codec.flush_pending();
                    if (this._codec.AvailableBytesOut == 0)
                    {
                        this.last_flush = -1;
                        return(0);
                    }
                }
            }
            if (flush != FlushType.Finish)
            {
                return(0);
            }
            if (!this.WantRfc1950HeaderBytes || this.Rfc1950BytesEmitted)
            {
                return(1);
            }
            this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & -16777216) >> 0x18);
            this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 0xff0000) >> 0x10);
            this.pending[this.pendingCount++] = (byte)((this._codec._Adler32 & 0xff00) >> 8);
            this.pending[this.pendingCount++] = (byte)(this._codec._Adler32 & 0xff);
            this._codec.flush_pending();
            this.Rfc1950BytesEmitted = true;
            return((this.pendingCount == 0) ? 1 : 0);
        }
        internal int Deflate(FlushType flush)
        {
            if (_codec.OutputBuffer == null || (_codec.InputBuffer == null && _codec.AvailableBytesIn != 0) || (status == FINISH_STATE && flush != FlushType.Finish))
            {
                _codec.Message = _ErrorMessage[4];
                throw new ZlibException($"Something is fishy. [{_codec.Message}]");
            }
            if (_codec.AvailableBytesOut == 0)
            {
                _codec.Message = _ErrorMessage[7];
                throw new ZlibException("OutputBuffer is full (AvailableBytesOut == 0)");
            }
            int num = last_flush;

            last_flush = (int)flush;
            if (status == INIT_STATE)
            {
                int num2 = Z_DEFLATED + (w_bits - 8 << 4) << 8;
                int num3 = (int)((compressionLevel - 1) & (CompressionLevel)255) >> 1;
                if (num3 > 3)
                {
                    num3 = 3;
                }
                num2 |= num3 << 6;
                if (strstart != 0)
                {
                    num2 |= PRESET_DICT;
                }
                num2  += 31 - num2 % 31;
                status = BUSY_STATE;
                pending[pendingCount++] = (byte)(num2 >> 8);
                pending[pendingCount++] = (byte)num2;
                if (strstart != 0)
                {
                    pending[pendingCount++] = (byte)((uint)((int)_codec._Adler32 & -16777216) >> 24);
                    pending[pendingCount++] = (byte)((_codec._Adler32 & 0xFF0000) >> 16);
                    pending[pendingCount++] = (byte)((_codec._Adler32 & 0xFF00) >> 8);
                    pending[pendingCount++] = (byte)(_codec._Adler32 & 0xFF);
                }
                _codec._Adler32 = Adler.Adler32(0u, null, 0, 0);
            }
            if (pendingCount != 0)
            {
                _codec.flush_pending();
                if (_codec.AvailableBytesOut == 0)
                {
                    last_flush = -1;
                    return(0);
                }
            }
            else if (_codec.AvailableBytesIn == 0 && (int)flush <= num && flush != FlushType.Finish)
            {
                return(0);
            }
            if (status == FINISH_STATE && _codec.AvailableBytesIn != 0)
            {
                _codec.Message = _ErrorMessage[7];
                throw new ZlibException("status == FINISH_STATE && _codec.AvailableBytesIn != 0");
            }
            if (_codec.AvailableBytesIn != 0 || lookahead != 0 || (flush != 0 && status != FINISH_STATE))
            {
                BlockState blockState = DeflateFunction(flush);
                if (blockState == BlockState.FinishStarted || blockState == BlockState.FinishDone)
                {
                    status = FINISH_STATE;
                }
                switch (blockState)
                {
                case BlockState.NeedMore:
                case BlockState.FinishStarted:
                    if (_codec.AvailableBytesOut == 0)
                    {
                        last_flush = -1;
                    }
                    return(0);

                case BlockState.BlockDone:
                    if (flush == FlushType.Partial)
                    {
                        _tr_align();
                    }
                    else
                    {
                        _tr_stored_block(0, 0, false);
                        if (flush == FlushType.Full)
                        {
                            for (int i = 0; i < hash_size; i++)
                            {
                                head[i] = 0;
                            }
                        }
                    }
                    _codec.flush_pending();
                    if (_codec.AvailableBytesOut == 0)
                    {
                        last_flush = -1;
                        return(0);
                    }
                    break;
                }
            }
            if (flush != FlushType.Finish)
            {
                return(0);
            }
            if (!WantRfc1950HeaderBytes || Rfc1950BytesEmitted)
            {
                return(1);
            }
            pending[pendingCount++] = (byte)((uint)((int)_codec._Adler32 & -16777216) >> 24);
            pending[pendingCount++] = (byte)((_codec._Adler32 & 0xFF0000) >> 16);
            pending[pendingCount++] = (byte)((_codec._Adler32 & 0xFF00) >> 8);
            pending[pendingCount++] = (byte)(_codec._Adler32 & 0xFF);
            _codec.flush_pending();
            Rfc1950BytesEmitted = true;
            return((pendingCount == 0) ? 1 : 0);
        }