=========================================================================== * Copy without compression as much as possible from the input stream, return * the current block state. * This function does not insert new strings in the dictionary since * uncompressible data is probably not useful. This function is used * only for the level=0 compression option. * NOTE: this function should be opt
| 1546 | * window to pending_buf. |
| 1547 | */ |
| 1548 | local block_state deflate_stored(deflate_state *s, int flush) |
| 1549 | { |
| 1550 | /* Stored blocks are limited to 0xffff bytes, pending_buf is limited |
| 1551 | * to pending_buf_size, and each stored block has a 5 byte header: |
| 1552 | */ |
| 1553 | ulg max_block_size = 0xffff; |
| 1554 | ulg max_start; |
| 1555 | |
| 1556 | if (max_block_size > s->pending_buf_size - 5) { |
| 1557 | max_block_size = s->pending_buf_size - 5; |
| 1558 | } |
| 1559 | |
| 1560 | /* Copy as much as possible from input to output: */ |
| 1561 | for (;;) { |
| 1562 | /* Fill the window as much as possible: */ |
| 1563 | if (s->lookahead <= 1) { |
| 1564 | |
| 1565 | Assert(s->strstart < s->w_size+MAX_DIST(s) || |
| 1566 | s->block_start >= (long)s->w_size, "slide too late"); |
| 1567 | |
| 1568 | fill_window(s); |
| 1569 | if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; |
| 1570 | |
| 1571 | if (s->lookahead == 0) break; /* flush the current block */ |
| 1572 | } |
| 1573 | Assert(s->block_start >= 0L, "block gone"); |
| 1574 | |
| 1575 | s->strstart += s->lookahead; |
| 1576 | s->lookahead = 0; |
| 1577 | |
| 1578 | if (flush == Z_INSERT_ONLY) { |
| 1579 | s->block_start = s->strstart; |
| 1580 | continue; |
| 1581 | } |
| 1582 | |
| 1583 | /* Emit a stored block if pending_buf will be full: */ |
| 1584 | max_start = s->block_start + max_block_size; |
| 1585 | if (s->strstart == 0 || (ulg)s->strstart >= max_start) { |
| 1586 | /* strstart == 0 is possible when wraparound on 16-bit machine */ |
| 1587 | s->lookahead = (uInt)(s->strstart - max_start); |
| 1588 | s->strstart = (uInt)max_start; |
| 1589 | FLUSH_BLOCK(s, 0); |
| 1590 | } |
| 1591 | /* Flush if we may have to slide, otherwise block_start may become |
| 1592 | * negative and the data will be gone: |
| 1593 | */ |
| 1594 | if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { |
| 1595 | FLUSH_BLOCK(s, 0); |
| 1596 | } |
| 1597 | } |
| 1598 | s->insert = 0; |
| 1599 | if (flush == Z_INSERT_ONLY) { |
| 1600 | s->block_start = s->strstart; |
| 1601 | return need_more; |
| 1602 | } |
| 1603 | if (flush == Z_FINISH) { |
| 1604 | FLUSH_BLOCK(s, 1); |
| 1605 | return finish_done; |
nothing calls this directly
no test coverage detected