=========================================================================== * Copy without compression as much as possible from the input stream, return * the current block state. * * In case deflateParams() is used to later switch to a non-zero compression * level, s->matches (otherwise unused when storing) keeps track of the number * of hash table slides to perform. If s->matches is 1, the
(s, flush)
| 1646 | * maximizes the opportunites to have a single copy from next_in to next_out. |
| 1647 | */ |
| 1648 | local block_state deflate_stored(s, flush) |
| 1649 | deflate_state *s; |
| 1650 | int flush; |
| 1651 | { |
| 1652 | /* Smallest worthy block size when not flushing or finishing. By default |
| 1653 | * this is 32K. This can be as small as 507 bytes for memLevel == 1. For |
| 1654 | * large input and output buffers, the stored block size will be larger. |
| 1655 | */ |
| 1656 | unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size); |
| 1657 | |
| 1658 | /* Copy as many min_block or larger stored blocks directly to next_out as |
| 1659 | * possible. If flushing, copy the remaining available input to next_out as |
| 1660 | * stored blocks, if there is enough space. |
| 1661 | */ |
| 1662 | unsigned len, left, have, last = 0; |
| 1663 | unsigned used = s->strm->avail_in; |
| 1664 | do { |
| 1665 | /* Set len to the maximum size block that we can copy directly with the |
| 1666 | * available input data and output space. Set left to how much of that |
| 1667 | * would be copied from what's left in the window. |
| 1668 | */ |
| 1669 | len = MAX_STORED; /* maximum deflate stored block length */ |
| 1670 | have = (s->bi_valid + 42) >> 3; /* number of header bytes */ |
| 1671 | if (s->strm->avail_out < have) /* need room for header */ |
| 1672 | break; |
| 1673 | /* maximum stored block length that will fit in avail_out: */ |
| 1674 | have = s->strm->avail_out - have; |
| 1675 | left = s->strstart - s->block_start; /* bytes left in window */ |
| 1676 | if (len > (ulg)left + s->strm->avail_in) |
| 1677 | len = left + s->strm->avail_in; /* limit len to the input */ |
| 1678 | if (len > have) |
| 1679 | len = have; /* limit len to the output */ |
| 1680 | |
| 1681 | /* If the stored block would be less than min_block in length, or if |
| 1682 | * unable to copy all of the available input when flushing, then try |
| 1683 | * copying to the window and the pending buffer instead. Also don't |
| 1684 | * write an empty block when flushing -- deflate() does that. |
| 1685 | */ |
| 1686 | if (len < min_block && ((len == 0 && flush != Z_FINISH) || |
| 1687 | flush == Z_NO_FLUSH || |
| 1688 | len != left + s->strm->avail_in)) |
| 1689 | break; |
| 1690 | |
| 1691 | /* Make a dummy stored block in pending to get the header bytes, |
| 1692 | * including any pending bits. This also updates the debugging counts. |
| 1693 | */ |
| 1694 | last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0; |
| 1695 | _tr_stored_block(s, (char *)0, 0L, last); |
| 1696 | |
| 1697 | /* Replace the lengths in the dummy stored block with len. */ |
| 1698 | s->pending_buf[s->pending - 4] = len; |
| 1699 | s->pending_buf[s->pending - 3] = len >> 8; |
| 1700 | s->pending_buf[s->pending - 2] = ~len; |
| 1701 | s->pending_buf[s->pending - 1] = ~len >> 8; |
| 1702 | |
| 1703 | /* Write the stored block header bytes. */ |
| 1704 | flush_pending(s->strm); |
| 1705 |
no test coverage detected