| 101 | } |
| 102 | |
| 103 | inline size_t Read(void* buf, size_t size) { |
| 104 | Z()->next_out = (unsigned char*)buf; |
| 105 | Z()->avail_out = size; |
| 106 | |
| 107 | while (true) { |
| 108 | if (Z()->avail_in == 0) { |
| 109 | if (!FillInputBuffer()) { |
| 110 | return 0; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | switch (inflate(Z(), Z_SYNC_FLUSH)) { |
| 115 | case Z_NEED_DICT: { |
| 116 | SetDict(); |
| 117 | continue; |
| 118 | } |
| 119 | |
| 120 | case Z_STREAM_END: { |
| 121 | if (AllowMultipleStreams_) { |
| 122 | if (inflateReset(Z()) != Z_OK) { |
| 123 | ythrow TZLibDecompressorError() << "inflate reset error(" << GetErrMsg() << ")"; |
| 124 | } |
| 125 | } else { |
| 126 | return size - Z()->avail_out; |
| 127 | } |
| 128 | |
| 129 | [[fallthrough]]; |
| 130 | } |
| 131 | |
| 132 | case Z_OK: { |
| 133 | const size_t processed = size - Z()->avail_out; |
| 134 | |
| 135 | if (processed) { |
| 136 | return processed; |
| 137 | } |
| 138 | |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | default: |
| 143 | ythrow TZLibDecompressorError() << "inflate error(" << GetErrMsg() << ")"; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | private: |
| 149 | inline bool FillInputBuffer() { |
no test coverage detected