function _tr_flush_block(s, buf, stored_len, last)
	//DeflateState *s;
	//charf *buf;       /* input block, or NULL if too old */
	//ulg stored_len;   /* length of input block */
	//int last;         /* one if this is the last block for a file */
	{
	  var opt_lenb, static_lenb;  /* opt_len and static_len in bytes */
	  var max_blindex = 0;        /* index of last bit length code of non zero freq */
	
	  /* Build the Huffman trees unless a stored block is forced */
	  if (s.level > 0) {
	
	    /* Check if the file is binary or text */
	    if (s.strm.data_type === Z_UNKNOWN) {
	      s.strm.data_type = detect_data_type(s);
	    }
	
	    /* Construct the literal and distance trees */
	    build_tree(s, s.l_desc);
	    // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
	    //        s->static_len));
	
	    build_tree(s, s.d_desc);
	    // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
	    //        s->static_len));
	    /* At this point, opt_len and static_len are the total bit lengths of
	     * the compressed block data, excluding the tree representations.
	     */
	
	    /* Build the bit length tree for the above two trees, and get the index
	     * in bl_order of the last bit length code to send.
	     */
	    max_blindex = build_bl_tree(s);
	
	    /* Determine the best encoding. Compute the block lengths in bytes. */
	    opt_lenb = (s.opt_len+3+7) >>> 3;
	    static_lenb = (s.static_len+3+7) >>> 3;
	
	    // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
	    //        opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
	    //        s->last_lit));
	
	    if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
	
	  } else {
	    // Assert(buf != (char*)0, "lost buf");
	    opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
	  }
	
	  if ((stored_len+4 <= opt_lenb) && (buf !== -1)) {
	    /* 4: two words for the lengths */
	
	    /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
	     * Otherwise we can't have processed more than WSIZE input bytes since
	     * the last block flush, because compression would have been
	     * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
	     * transform a block into a stored block.
	     */
	    _tr_stored_block(s, buf, stored_len, last);
	
	  } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
	
	    send_bits(s, (STATIC_TREES<<1) + (last ? 1 : 0), 3);
	    compress_block(s, static_ltree, static_dtree);
	
	  } else {
	    send_bits(s, (DYN_TREES<<1) + (last ? 1 : 0), 3);
	    send_all_trees(s, s.l_desc.max_code+1, s.d_desc.max_code+1, max_blindex+1);
	    compress_block(s, s.dyn_ltree, s.dyn_dtree);
	  }
	  // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
	  /* The above check is made mod 2^32, for files larger than 512 MB
	   * and uLong implemented on 32 bits.
	   */
	  init_block(s);
	
	  if (last) {
	    bi_windup(s);
	  }
	  // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
	  //       s->compressed_len-7*last));
	}
/* ===========================================================================
	 * Determine the best encoding for the current block: dynamic trees, static
	 * trees or store, and output the encoded block to the zip file.
	 */
Determine the best encoding for the current block: dynamic trees, static
trees or store, and output the encoded block to the zip file.
Determine the best encoding for the current block : dynamic trees static trees or store and output the encoded block to the zip file .
function _tr_flush_block(s, buf, stored_len, last)
	{
	  var opt_lenb, static_lenb;  
	  var max_blindex = 0;        
	  if (s.level > 0) {
	    if (s.strm.data_type === Z_UNKNOWN) {
	      s.strm.data_type = detect_data_type(s);
	    }
	    build_tree(s, s.l_desc);
	    build_tree(s, s.d_desc);
	    max_blindex = build_bl_tree(s);
	    opt_lenb = (s.opt_len+3+7) >>> 3;
	    static_lenb = (s.static_len+3+7) >>> 3;
	    if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
	  } else {
	    opt_lenb = static_lenb = stored_len + 5; 
	  }
	  if ((stored_len+4 <= opt_lenb) && (buf !== -1)) {
	    _tr_stored_block(s, buf, stored_len, last);
	  } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
	    send_bits(s, (STATIC_TREES<<1) + (last ? 1 : 0), 3);
	    compress_block(s, static_ltree, static_dtree);
	  } else {
	    send_bits(s, (DYN_TREES<<1) + (last ? 1 : 0), 3);
	    send_all_trees(s, s.l_desc.max_code+1, s.d_desc.max_code+1, max_blindex+1);
	    compress_block(s, s.dyn_ltree, s.dyn_dtree);
	  }
	  init_block(s);
	  if (last) {
	    bi_windup(s);
	  }
	}
function _tr_flush_block ( s , buf , stored_len , last ) { var opt_lenb , static_lenb ; var max_blindex = 0 ; if ( s . level > 0 ) { if ( s . strm . data_type === Z_UNKNOWN ) { s . strm . data_type = detect_data_type ( s ) ; } build_tree ( s , s . l_desc ) ; build_tree ( s , s . d_desc ) ; max_blindex = build_bl_tree ( s ) ; opt_lenb = ( s . opt_len + 3 + 7 ) >>> 3 ; static_lenb = ( s . static_len + 3 + 7 ) >>> 3 ; if ( static_lenb <= opt_lenb ) { opt_lenb = static_lenb ; } } else { opt_lenb = static_lenb = stored_len + 5 ; } if ( ( stored_len + 4 <= opt_lenb ) && ( buf !== - 1 ) ) { _tr_stored_block ( s , buf , stored_len , last ) ; } else if ( s . strategy === Z_FIXED || static_lenb === opt_lenb ) { send_bits ( s , ( STATIC_TREES << 1 ) + ( last ? 1 : 0 ) , 3 ) ; compress_block ( s , static_ltree , static_dtree ) ; } else { send_bits ( s , ( DYN_TREES << 1 ) + ( last ? 1 : 0 ) , 3 ) ; send_all_trees ( s , s . l_desc . max_code + 1 , s . d_desc . max_code + 1 , max_blindex + 1 ) ; compress_block ( s , s . dyn_ltree , s . dyn_dtree ) ; } init_block ( s ) ; if ( last ) { bi_windup ( s ) ; } }
Determine the best encoding for the current block: dynamic trees, static
 trees or store, and output the encoded block to the zip file.
Determine the best encoding for the current block : dynamic trees static trees or store and output the encoded block to the zip file .
//DeflateState *s; //charf *buf;       /* input block, or NULL if too old */ //ulg stored_len;   /* length of input block */ //int last;         /* one if this is the last block for a file */ /* opt_len and static_len in bytes */ /* index of last bit length code of non zero freq */ /* Build the Huffman trees unless a stored block is forced */ /* Check if the file is binary or text */ /* Construct the literal and distance trees */ // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, //        s->static_len)); // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, //        s->static_len)); /* At this point, opt_len and static_len are the total bit lengths of
	     * the compressed block data, excluding the tree representations.
	     */ /* Build the bit length tree for the above two trees, and get the index
	     * in bl_order of the last bit length code to send.
	     */ /* Determine the best encoding. Compute the block lengths in bytes. */ // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", //        opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, //        s->last_lit)); // Assert(buf != (char*)0, "lost buf"); /* force a stored block */ /* 4: two words for the lengths */ /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
	     * Otherwise we can't have processed more than WSIZE input bytes since
	     * the last block flush, because compression would have been
	     * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
	     * transform a block into a stored block.
	     */ // Assert (s->compressed_len == s->bits_sent, "bad compressed size"); /* The above check is made mod 2^32, for files larger than 512 MB
	   * and uLong implemented on 32 bits.
	   */ // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, //       s->compressed_len-7*last));