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

Function gz_decomp

freebsd/contrib/zstd/zlibWrapper/gzread.c:187–233  ·  view source on GitHub ↗

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

(state)

Source from the content-addressed store, hash-verified

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