MCPcopy Create free account
hub / github.com/TruthHun/BookStack / _tr_flush_block

Function _tr_flush_block

static/word2md/mammoth.browser.js:23406–23487  ·  view source on GitHub ↗
(s, buf, stored_len, last)

Source from the content-addressed store, hash-verified

23404 * trees or store, and output the encoded block to the zip file.
23405 */
23406function _tr_flush_block(s, buf, stored_len, last)
23407//DeflateState *s;
23408//charf *buf; /* input block, or NULL if too old */
23409//ulg stored_len; /* length of input block */
23410//int last; /* one if this is the last block for a file */
23411{
23412 var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
23413 var max_blindex = 0; /* index of last bit length code of non zero freq */
23414
23415 /* Build the Huffman trees unless a stored block is forced */
23416 if (s.level > 0) {
23417
23418 /* Check if the file is binary or text */
23419 if (s.strm.data_type === Z_UNKNOWN) {
23420 s.strm.data_type = detect_data_type(s);
23421 }
23422
23423 /* Construct the literal and distance trees */
23424 build_tree(s, s.l_desc);
23425 // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
23426 // s->static_len));
23427
23428 build_tree(s, s.d_desc);
23429 // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
23430 // s->static_len));
23431 /* At this point, opt_len and static_len are the total bit lengths of
23432 * the compressed block data, excluding the tree representations.
23433 */
23434
23435 /* Build the bit length tree for the above two trees, and get the index
23436 * in bl_order of the last bit length code to send.
23437 */
23438 max_blindex = build_bl_tree(s);
23439
23440 /* Determine the best encoding. Compute the block lengths in bytes. */
23441 opt_lenb = (s.opt_len + 3 + 7) >>> 3;
23442 static_lenb = (s.static_len + 3 + 7) >>> 3;
23443
23444 // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
23445 // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
23446 // s->last_lit));
23447
23448 if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
23449
23450 } else {
23451 // Assert(buf != (char*)0, "lost buf");
23452 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
23453 }
23454
23455 if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
23456 /* 4: two words for the lengths */
23457
23458 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
23459 * Otherwise we can't have processed more than WSIZE input bytes since
23460 * the last block flush, because compression would have been
23461 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
23462 * transform a block into a stored block.
23463 */

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