MCPcopy Create free account
hub / github.com/hoothin/UserScripts / _tr_flush_block

Function _tr_flush_block

Picviewer CE+/dist.user.js:11424–11505  ·  view source on GitHub ↗
(s, buf, stored_len, last)

Source from the content-addressed store, hash-verified

11422 * trees or store, and output the encoded block to the zip file.
11423 */
11424function _tr_flush_block(s, buf, stored_len, last)
11425//DeflateState *s;
11426//charf *buf; /* input block, or NULL if too old */
11427//ulg stored_len; /* length of input block */
11428//int last; /* one if this is the last block for a file */
11429{
11430 var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
11431 var max_blindex = 0; /* index of last bit length code of non zero freq */
11432
11433 /* Build the Huffman trees unless a stored block is forced */
11434 if (s.level > 0) {
11435
11436 /* Check if the file is binary or text */
11437 if (s.strm.data_type === Z_UNKNOWN) {
11438 s.strm.data_type = detect_data_type(s);
11439 }
11440
11441 /* Construct the literal and distance trees */
11442 build_tree(s, s.l_desc);
11443 // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
11444 // s->static_len));
11445
11446 build_tree(s, s.d_desc);
11447 // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
11448 // s->static_len));
11449 /* At this point, opt_len and static_len are the total bit lengths of
11450 * the compressed block data, excluding the tree representations.
11451 */
11452
11453 /* Build the bit length tree for the above two trees, and get the index
11454 * in bl_order of the last bit length code to send.
11455 */
11456 max_blindex = build_bl_tree(s);
11457
11458 /* Determine the best encoding. Compute the block lengths in bytes. */
11459 opt_lenb = (s.opt_len + 3 + 7) >>> 3;
11460 static_lenb = (s.static_len + 3 + 7) >>> 3;
11461
11462 // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
11463 // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
11464 // s->last_lit));
11465
11466 if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
11467
11468 } else {
11469 // Assert(buf != (char*)0, "lost buf");
11470 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
11471 }
11472
11473 if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
11474 /* 4: two words for the lengths */
11475
11476 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
11477 * Otherwise we can't have processed more than WSIZE input bytes since
11478 * the last block flush, because compression would have been
11479 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
11480 * transform a block into a stored block.
11481 */

Callers

nothing calls this directly

Calls 9

detect_data_typeFunction · 0.70
build_treeFunction · 0.70
build_bl_treeFunction · 0.70
_tr_stored_blockFunction · 0.70
send_bitsFunction · 0.70
compress_blockFunction · 0.70
send_all_treesFunction · 0.70
init_blockFunction · 0.70
bi_windupFunction · 0.70

Tested by

no test coverage detected