MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / gz_decomp

Function gz_decomp

extern/zlib/src/gzread.c:156–200  ·  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. */

Source from the content-addressed store, hash-verified

154 the next gzip stream or raw data, once state->x.have is depleted. Returns 0
155 on success, -1 on failure. */
156local int gz_decomp(gz_statep state) {
157 int ret = Z_OK;
158 unsigned had;
159 z_streamp strm = &(state->strm);
160
161 /* fill output buffer up to end of deflate stream */
162 had = strm->avail_out;
163 do {
164 /* get more input for inflate() */
165 if (strm->avail_in == 0 && gz_avail(state) == -1)
166 return -1;
167 if (strm->avail_in == 0) {
168 gz_error(state, Z_BUF_ERROR, "unexpected end of file");
169 break;
170 }
171
172 /* decompress and handle errors */
173 ret = inflate(strm, Z_NO_FLUSH);
174 if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) {
175 gz_error(state, Z_STREAM_ERROR,
176 "internal error: inflate stream corrupt");
177 return -1;
178 }
179 if (ret == Z_MEM_ERROR) {
180 gz_error(state, Z_MEM_ERROR, "out of memory");
181 return -1;
182 }
183 if (ret == Z_DATA_ERROR) { /* deflate stream invalid */
184 gz_error(state, Z_DATA_ERROR,
185 strm->msg == NULL ? "compressed data error" : strm->msg);
186 return -1;
187 }
188 } while (strm->avail_out && ret != Z_STREAM_END);
189
190 /* update available output */
191 state->x.have = had - strm->avail_out;
192 state->x.next = strm->next_out - state->x.have;
193
194 /* if the gzip stream completed successfully, look for another */
195 if (ret == Z_STREAM_END)
196 state->how = LOOK;
197
198 /* good decompression */
199 return 0;
200}
201
202/* Fetch data and put it in the output buffer. Assumes state->x.have is 0.
203 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