MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / deflate_stored

Function deflate_stored

extern/zlib/src/deflate.c:1627–1802  ·  view source on GitHub ↗

=========================================================================== * 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

Source from the content-addressed store, hash-verified

1625 * maximizes the opportunities to have a single copy from next_in to next_out.
1626 */
1627local block_state deflate_stored(deflate_state *s, int flush) {
1628 /* Smallest worthy block size when not flushing or finishing. By default
1629 * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
1630 * large input and output buffers, the stored block size will be larger.
1631 */
1632 unsigned min_block = MIN(s->pending_buf_size - 5, s->w_size);
1633
1634 /* Copy as many min_block or larger stored blocks directly to next_out as
1635 * possible. If flushing, copy the remaining available input to next_out as
1636 * stored blocks, if there is enough space.
1637 */
1638 unsigned len, left, have, last = 0;
1639 unsigned used = s->strm->avail_in;
1640 do {
1641 /* Set len to the maximum size block that we can copy directly with the
1642 * available input data and output space. Set left to how much of that
1643 * would be copied from what's left in the window.
1644 */
1645 len = MAX_STORED; /* maximum deflate stored block length */
1646 have = (s->bi_valid + 42) >> 3; /* number of header bytes */
1647 if (s->strm->avail_out < have) /* need room for header */
1648 break;
1649 /* maximum stored block length that will fit in avail_out: */
1650 have = s->strm->avail_out - have;
1651 left = s->strstart - s->block_start; /* bytes left in window */
1652 if (len > (ulg)left + s->strm->avail_in)
1653 len = left + s->strm->avail_in; /* limit len to the input */
1654 if (len > have)
1655 len = have; /* limit len to the output */
1656
1657 /* If the stored block would be less than min_block in length, or if
1658 * unable to copy all of the available input when flushing, then try
1659 * copying to the window and the pending buffer instead. Also don't
1660 * write an empty block when flushing -- deflate() does that.
1661 */
1662 if (len < min_block && ((len == 0 && flush != Z_FINISH) ||
1663 flush == Z_NO_FLUSH ||
1664 len != left + s->strm->avail_in))
1665 break;
1666
1667 /* Make a dummy stored block in pending to get the header bytes,
1668 * including any pending bits. This also updates the debugging counts.
1669 */
1670 last = flush == Z_FINISH && len == left + s->strm->avail_in ? 1 : 0;
1671 _tr_stored_block(s, (char *)0, 0L, last);
1672
1673 /* Replace the lengths in the dummy stored block with len. */
1674 s->pending_buf[s->pending - 4] = len;
1675 s->pending_buf[s->pending - 3] = len >> 8;
1676 s->pending_buf[s->pending - 2] = ~len;
1677 s->pending_buf[s->pending - 1] = ~len >> 8;
1678
1679 /* Write the stored block header bytes. */
1680 flush_pending(s->strm);
1681
1682#ifdef ZLIB_DEBUG
1683 /* Update debugging counts for the data about to be copied. */
1684 s->compressed_len += len << 3;

Callers 1

deflateFunction · 0.85

Calls 4

_tr_stored_blockFunction · 0.85
flush_pendingFunction · 0.85
zmemcpyFunction · 0.85
read_bufFunction · 0.85

Tested by

no test coverage detected