Exemplo n.º 1
0
        public ZLibStatus InflateSetDictionary(byte[] dictionary, int dictLength)
        {
            int index  = 0;
            int length = dictLength;

            if (this._mode != InflateMode.DICT0)
            {
                return(ZLibStatus.Z_STREAM_ERROR);
            }

            if (Adler32.adler32(1L, dictionary, 0, dictLength) != base.adler)
            {
                return(ZLibStatus.Z_DATA_ERROR);
            }

            base.adler = Adler32.adler32(0, null, 0, 0);

            if (length >= (1 << this._wbits))
            {
                length = (1 << this._wbits) - 1;
                index  = dictLength - length;
            }
            this._blocks.set_dictionary(dictionary, index, length);
            this._mode = InflateMode.BLOCKS;
            return(ZLibStatus.Z_OK);
        }
Exemplo n.º 2
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=avail_in;

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

            avail_in-=len;

            if(dstate.noheader==0) {
                adler=_adler.adler32(adler, next_in, next_in_index, len);
            }
            System.Array.Copy(next_in, next_in_index, buf, start, len);
            next_in_index  += len;
            total_in += len;
            return len;
        }
Exemplo n.º 3
0
        internal void reset(ICompressor z, long[] c)
        {
            if (c != null)
            {
                c[0] = check;
            }
            if (mode == InflateBlockMode.BTREE || mode == InflateBlockMode.DTREE)
            {
            }

            mode = InflateBlockMode.TYPE;
            bitk = 0;
            bitb = 0;
            read = write = 0;

            if (checkfn != null)
            {
                z.adler = check = Adler32.adler32(0L, null, 0, 0);
            }
        }
Exemplo n.º 4
0
        internal int read_buf(byte[] buf, int start, int size)
        {
            int num = avail_in;

            if (num > size)
            {
                num = size;
            }
            if (num == 0)
            {
                return(0);
            }
            avail_in -= num;
            if (dstate.noheader == 0)
            {
                adler = _adler.adler32(adler, next_in, next_in_index, num);
            }
            global::System.Array.Copy((global::System.Array)next_in, next_in_index, (global::System.Array)buf, start, num);
            next_in_index += num;
            total_in      += num;
            return(num);
        }
Exemplo n.º 5
0
        internal void reset(ZStream z, long[] c)
        {
            if (c != null)
            {
                c[0] = check;
            }
            if (mode == InflateBlockMode.BTREE || mode == InflateBlockMode.DTREE)
            {
            }
            if (mode == InflateBlockMode.CODES)
            {
                codesfree(z);
            }
            mode = InflateBlockMode.TYPE;
            bitk = 0;
            bitb = 0;
            read = write = 0;

            if (checkfn != null)
            {
                z.adler = check = Adler32.adler32(0L, null, 0, 0);
            }
        }
Exemplo n.º 6
0
        // copy as much as possible from the sliding window to the output area
        internal ZLibStatus inflate_flush(ICompressor z, ZLibStatus r)
        {
            int n;
            int p;
            int q;

            // local copies of source and destination pointers
            p = z.next_out_index;
            q = read;

            // compute number of bytes to copy as far as end of window
            n = (int)((q <= write ? write : end) - q);
            if (n > z.avail_out)
            {
                n = z.avail_out;
            }
            if (n != 0 && r == ZLibStatus.Z_BUF_ERROR)
            {
                r = ZLibStatus.Z_OK;
            }

            // update counters
            z.avail_out -= n;
            z.total_out += n;

            // update check information
            if (checkfn != null)
            {
                z.adler = check = Adler32.adler32(check, window, q, n);
            }

            // copy as far as end of window
            System.Array.Copy(window, q, z.next_out, p, n);
            p += n;
            q += n;

            // see if more to copy at beginning of window
            if (q == end)
            {
                // wrap pointers
                q = 0;
                if (write == end)
                {
                    write = 0;
                }

                // compute bytes to copy
                n = write - q;
                if (n > z.avail_out)
                {
                    n = z.avail_out;
                }
                if (n != 0 && r == ZLibStatus.Z_BUF_ERROR)
                {
                    r = ZLibStatus.Z_OK;
                }

                // update counters
                z.avail_out -= n;
                z.total_out += n;

                // update check information
                if (checkfn != null)
                {
                    z.adler = check = Adler32.adler32(check, window, q, n);
                }

                // copy
                System.Array.Copy(window, q, z.next_out, p, n);
                p += n;
                q += n;
            }

            // update pointers
            z.next_out_index = p;
            read             = q;

            // done
            return(r);
        }