MCPcopy Create free account
hub / github.com/F-Stack/f-stack / gz_decomp

Function gz_decomp

freebsd/contrib/zlib/gzread.c:178–224  ·  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

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

Callers 2

gz_fetchFunction · 0.70
gz_readFunction · 0.70

Calls 2

gz_availFunction · 0.70
gz_errorFunction · 0.70

Tested by

no test coverage detected