ComponentAce.Compression.Libs.ZLib.Deflate.compress_block C# (CSharp) Method

compress_block() private method

Send the block data compressed using the given Huffman trees
private compress_block ( short ltree, short dtree ) : void
ltree short
dtree short
return void
        private void compress_block(short[] ltree, short[] dtree)
        {
            int dist; // distance of matched string
            int lc; // match length or unmatched char (if dist == 0)
            int lx = 0; // running index in l_buf
            int code; // the code to send
            int extra; // number of extra bits to send

            if (last_lit != 0)
            {
                do
                {
                    dist = ((Pending_buf[d_buf + lx * 2] << 8) & 0xff00) | (Pending_buf[d_buf + lx * 2 + 1] & 0xff);
                    lc = (Pending_buf[l_buf + lx]) & 0xff; lx++;

                    if (dist == 0)
                    {
                        send_code(lc, ltree); // send a literal byte
                    }
                    else
                    {
                        // Here, lc is the match length - MIN_MATCH
                        code = ZLibUtil._length_code[lc];

                        send_code(code + LITERALS + 1, ltree); // send the length code
                        extra = ZLibUtil.extra_lbits[code];
                        if (extra != 0)
                        {
                            lc -= ZLibUtil.base_length[code];
                            send_bits(lc, extra); // send the extra length bits
                        }
                        dist--; // dist is now the match distance - 1
                        code = Tree.d_code(dist);

                        send_code(code, dtree); // send the distance code
                        extra = ZLibUtil.extra_dbits[code];
                        if (extra != 0)
                        {
                            dist -= ZLibUtil.base_dist[code];
                            send_bits(dist, extra); // send the extra distance bits
                        }
                    } // literal or match pair ?

                    // Check that the overlay between Pending_buf and d_buf+l_buf is ok:
                }
                while (lx < last_lit);
            }

            send_code(END_BLOCK, ltree);
            last_eob_len = ltree[END_BLOCK * 2 + 1];
        }