function zip_build_bl_tree()

in themes/docsy/static/js/deflate.js [1319:1345]


    function zip_build_bl_tree() {
        var max_blindex;  // index of last bit length code of non zero freq

        // Determine the bit length frequencies for literal and distance trees
        zip_scan_tree(zip_dyn_ltree, zip_l_desc.max_code);
        zip_scan_tree(zip_dyn_dtree, zip_d_desc.max_code);

        // Build the bit length tree:
        zip_build_tree(zip_bl_desc);
        /* opt_len now includes the length of the tree representations, except
            * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
            */

        /* Determine the number of bit length codes to send. The pkzip format
            * requires that at least 4 bit length codes be sent. (appnote.txt says
            * 3 but the actual value used is 4.)
            */
        for (max_blindex = zip_BL_CODES - 1; max_blindex >= 3; max_blindex--) {
            if (zip_bl_tree[zip_bl_order[max_blindex]].dl != 0) break;
        }
        /* Update opt_len to include the bit length tree and counts */
        zip_opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
        //    Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
        //	    encoder->opt_len, encoder->static_len));

        return max_blindex;
    }