Example #1
0
        internal int SetDictionary(byte[] dictionary)
        {
            int index  = 0;
            int length = dictionary.Length;

            if (mode != InflateManagerMode.DICT0)
            {
                throw new IOException("Stream error.");
            }

            if (Adler.Adler32(1, dictionary, 0, dictionary.Length) != _codec._Adler32)
            {
                return(ZConstants.Z_DATA_ERROR);
            }

            _codec._Adler32 = Adler.Adler32(0, null, 0, 0);

            if (length >= (1 << wbits))
            {
                length = (1 << wbits) - 1;
                index  = dictionary.Length - length;
            }
            blocks.SetDictionary(dictionary, index, length);
            mode = InflateManagerMode.BLOCKS;
            return(ZConstants.Z_OK);
        }
Example #2
0
        internal uint Reset()
        {
            uint oldCheck = check;

            mode   = InflateBlockMode.TYPE;
            bitk   = 0;
            bitb   = 0;
            readAt = writeAt = 0;

            if (checkfn != null)
            {
                _codec._Adler32 = check = Adler.Adler32(0, null, 0, 0);
            }
            return(oldCheck);
        }
Example #3
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);
        }
Example #4
0
        // copy as much as possible from the sliding window to the output area
        internal int Flush(int r)
        {
            int nBytes;

            for (int pass = 0; pass < 2; pass++)
            {
                if (pass == 0)
                {
                    // compute number of bytes to copy as far as end of window
                    nBytes = (int)((readAt <= writeAt ? writeAt : end) - readAt);
                }
                else
                {
                    // compute bytes to copy
                    nBytes = writeAt - readAt;
                }

                // workitem 8870
                if (nBytes == 0)
                {
                    if (r == ZConstants.Z_BUF_ERROR)
                    {
                        r = ZConstants.Z_OK;
                    }
                    return(r);
                }

                if (nBytes > _codec.AvailableBytesOut)
                {
                    nBytes = _codec.AvailableBytesOut;
                }

                if (nBytes != 0 && r == ZConstants.Z_BUF_ERROR)
                {
                    r = ZConstants.Z_OK;
                }

                // update counters
                _codec.AvailableBytesOut -= nBytes;
                _codec.TotalBytesOut     += nBytes;

                // update check information
                if (checkfn != null)
                {
                    _codec._Adler32 = check = Adler.Adler32(check, window, readAt, nBytes);
                }

                // copy as far as end of window
                Array.Copy(window, readAt, _codec.OutputBuffer, _codec.NextOut, nBytes);
                _codec.NextOut += nBytes;
                readAt         += nBytes;

                // see if more to copy at beginning of window
                if (readAt == end && pass == 0)
                {
                    // wrap pointers
                    readAt = 0;
                    if (writeAt == end)
                    {
                        writeAt = 0;
                    }
                }
                else
                {
                    pass++;
                }
            }

            // done
            return(r);
        }