| 1698 | } |
| 1699 | |
| 1700 | int mz_inflate(mz_streamp pStream, int flush) { |
| 1701 | inflate_state *pState; |
| 1702 | mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32; |
| 1703 | size_t in_bytes, out_bytes, orig_avail_in; |
| 1704 | tinfl_status status; |
| 1705 | |
| 1706 | if ((!pStream) || (!pStream->state)) |
| 1707 | return MZ_STREAM_ERROR; |
| 1708 | if (flush == MZ_PARTIAL_FLUSH) |
| 1709 | flush = MZ_SYNC_FLUSH; |
| 1710 | if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) |
| 1711 | return MZ_STREAM_ERROR; |
| 1712 | |
| 1713 | pState = (inflate_state *)pStream->state; |
| 1714 | if (pState->m_window_bits > 0) |
| 1715 | decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER; |
| 1716 | orig_avail_in = pStream->avail_in; |
| 1717 | |
| 1718 | first_call = pState->m_first_call; |
| 1719 | pState->m_first_call = 0; |
| 1720 | if (pState->m_last_status < 0) |
| 1721 | return MZ_DATA_ERROR; |
| 1722 | |
| 1723 | if (pState->m_has_flushed && (flush != MZ_FINISH)) |
| 1724 | return MZ_STREAM_ERROR; |
| 1725 | pState->m_has_flushed |= (flush == MZ_FINISH); |
| 1726 | |
| 1727 | if ((flush == MZ_FINISH) && (first_call)) { |
| 1728 | // MZ_FINISH on the first call implies that the input and output buffers are |
| 1729 | // large enough to hold the entire compressed/decompressed file. |
| 1730 | decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF; |
| 1731 | in_bytes = pStream->avail_in; |
| 1732 | out_bytes = pStream->avail_out; |
| 1733 | status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, |
| 1734 | pStream->next_out, pStream->next_out, &out_bytes, |
| 1735 | decomp_flags); |
| 1736 | pState->m_last_status = status; |
| 1737 | pStream->next_in += (mz_uint)in_bytes; |
| 1738 | pStream->avail_in -= (mz_uint)in_bytes; |
| 1739 | pStream->total_in += (mz_uint)in_bytes; |
| 1740 | pStream->adler = tinfl_get_adler32(&pState->m_decomp); |
| 1741 | pStream->next_out += (mz_uint)out_bytes; |
| 1742 | pStream->avail_out -= (mz_uint)out_bytes; |
| 1743 | pStream->total_out += (mz_uint)out_bytes; |
| 1744 | |
| 1745 | if (status < 0) |
| 1746 | return MZ_DATA_ERROR; |
| 1747 | else if (status != TINFL_STATUS_DONE) { |
| 1748 | pState->m_last_status = TINFL_STATUS_FAILED; |
| 1749 | return MZ_BUF_ERROR; |
| 1750 | } |
| 1751 | return MZ_STREAM_END; |
| 1752 | } |
| 1753 | // flush != MZ_FINISH then we must assume there's more input. |
| 1754 | if (flush != MZ_FINISH) |
| 1755 | decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT; |
| 1756 | |
| 1757 | if (pState->m_dict_avail) { |
no test coverage detected