MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / gz_decomp

Function gz_decomp

extlibs/minizip/src/gzread.c:192–245  ·  view source on GitHub ↗

Decompress from input to the provided next_out and avail_out in the state. On return, state->x.have and state->x.next point to the just decompressed data. If the gzip stream completes, state->how is reset to LOOK to look for the next gzip stream or raw data, once state->x.have is depleted. Returns 0 on success, -1 on failure. */

(state)

Source from the content-addressed store, hash-verified

190 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
191 on success, -1 on failure. */
192local int gz_decomp(state)
193
194gz_statep state;
195{
196 int ret = Z_OK;
197 unsigned had;
198 z_streamp strm = &(state->strm);
199
200 /* fill output buffer up to end of deflate stream */
201 had = strm->avail_out;
202 do
203 {
204 /* get more input for inflate() */
205 if (strm->avail_in == 0 && gz_avail(state) == -1)
206 return -1;
207 if (strm->avail_in == 0)
208 {
209 gz_error(state, Z_BUF_ERROR, "unexpected end of file");
210 break;
211 }
212
213 /* decompress and handle errors */
214 ret = inflate(strm, Z_NO_FLUSH);
215 if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT)
216 {
217 gz_error(state, Z_STREAM_ERROR,
218 "internal error: inflate stream corrupt");
219 return -1;
220 }
221 if (ret == Z_MEM_ERROR)
222 {
223 gz_error(state, Z_MEM_ERROR, "out of memory");
224 return -1;
225 }
226 if (ret == Z_DATA_ERROR)
227 { /* deflate stream invalid */
228 gz_error(state, Z_DATA_ERROR,
229 strm->msg == NULL ? "compressed data error" : strm->msg);
230 return -1;
231 }
232 }
233 while (strm->avail_out && ret != Z_STREAM_END);
234
235 /* update available output */
236 state->x.have = had - strm->avail_out;
237 state->x.next = strm->next_out - state->x.have;
238
239 /* if the gzip stream completed successfully, look for another */
240 if (ret == Z_STREAM_END)
241 state->how = LOOK;
242
243 /* good decompression */
244 return 0;
245}
246
247/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
248 Data is either copied from the input file or decompressed from the input

Callers 2

gz_fetchFunction · 0.85
gz_readFunction · 0.85

Calls 2

gz_availFunction · 0.85
gz_errorFunction · 0.85

Tested by

no test coverage detected