Example #1
0
        /// <summary>
        /// copy as much as possible from the sliding Window to the output area
        /// </summary>
        internal int inflate_flush(ZStream z, int r)
        {
            int n;
            int p;
            int q;

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

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

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

            // update check information
            if (this.needCheck)
            {
                z.adler = check = Adler32.GetAdler32Checksum(check, Window, q, n);
            }

            // copy as far as End of Window
            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 (WritePos == End)
                {
                    WritePos = 0;
                }

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

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

                // update check information
                if (this.needCheck)
                {
                    z.adler = check = Adler32.GetAdler32Checksum(check, Window, q, n);
                }

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

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

            // done
            return(r);
        }