#define QUICK_START_BLOCK(s, last) { \
zng_tr_emit_tree(s, STATIC_TREES, last); \
- s->block_open = 1; \
+ s->block_open = 1 + last; \
s->block_start = s->strstart; \
}
unsigned dist, match_len, last;
- if (s->block_open == 0 && s->lookahead > 0) {
+ last = (flush == Z_FINISH) ? 1 : 0;
+ if (last && s->block_open != 2) {
+ /* Emit end of previous block */
+ QUICK_END_BLOCK(s, 0);
+ /* Emit start of last block */
+ QUICK_START_BLOCK(s, last);
+ } else if (s->block_open == 0 && s->lookahead > 0) {
/* Start new block only when we have lookahead data, so that if no
input data is given an empty block will not be written */
- last = (flush == Z_FINISH) ? 1 : 0;
QUICK_START_BLOCK(s, last);
}
if (s->pending + ((BIT_BUF_SIZE + 7) >> 3) >= s->pending_buf_size) {
flush_pending(s->strm);
if (s->strm->avail_out == 0 && flush != Z_FINISH) {
- /* Break to emit end block and return need_more */
- break;
+ return need_more;
}
}
if (s->lookahead < MIN_LOOKAHEAD) {
fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
- /* Always emit end block, in case next call is with Z_FINISH,
- and we need to emit start of last block */
- QUICK_END_BLOCK(s, 0);
return need_more;
}
if (s->lookahead == 0)
if (s->block_open == 0) {
/* Start new block when we have lookahead data, so that if no
input data is given an empty block will not be written */
- last = (flush == Z_FINISH) ? 1 : 0;
QUICK_START_BLOCK(s, last);
}
}
s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1;
- last = (flush == Z_FINISH) ? 1 : 0;
QUICK_END_BLOCK(s, last);
flush_pending(s->strm);