Example #1
0
        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);
        }
Example #2
0
 internal int Flush(int r)
 {
     for (int i = 0; i < 2; i++)
     {
         int len = (i != 0) ? (this.writeAt - this.readAt) : (((this.readAt > this.writeAt) ? this.end : this.writeAt) - this.readAt);
         if (len == 0)
         {
             if (r == -5)
             {
                 r = 0;
             }
             return(r);
         }
         if (len > this._codec.AvailableBytesOut)
         {
             len = this._codec.AvailableBytesOut;
         }
         if ((len != 0) && (r == -5))
         {
             r = 0;
         }
         this._codec.AvailableBytesOut -= len;
         this._codec.TotalBytesOut     += len;
         if (this.checkfn != null)
         {
             this._codec._Adler32 = this.check = Adler.Adler32(this.check, this.window, this.readAt, len);
         }
         Array.Copy(this.window, this.readAt, this._codec.OutputBuffer, this._codec.NextOut, len);
         this._codec.NextOut += len;
         this.readAt         += len;
         if ((this.readAt != this.end) || (i != 0))
         {
             i++;
         }
         else
         {
             this.readAt = 0;
             if (this.writeAt == this.end)
             {
                 this.writeAt = 0;
             }
         }
     }
     return(r);
 }
Example #3
0
        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);
        }
Example #4
0
        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 >= (1 << (this.wbits & 0x1f)))
            {
                length = (1 << (this.wbits & 0x1f)) - 1;
                start  = dictionary.Length - length;
            }
            this.blocks.SetDictionary(dictionary, start, length);
            this.mode = InflateManagerMode.BLOCKS;
            return(0);
        }
Example #5
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);
        }