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

Function gz_read

extlibs/minizip/src/gzread.c:324–411  ·  view source on GitHub ↗

Read len bytes into buf from file, or less than len up to the end of the input. Return the number of bytes read. If zero is returned, either the end of file was reached, or there was an error. state->err must be consulted in that case to determine which. */

(state, buf, len)

Source from the content-addressed store, hash-verified

322 end of file was reached, or there was an error. state->err must be
323 consulted in that case to determine which. */
324local z_size_t gz_read(state, buf, len)
325gz_statep state;
326voidp buf;
327
328z_size_t len;
329{
330 z_size_t got;
331 unsigned n;
332
333 /* if len is zero, avoid unnecessary operations */
334 if (len == 0)
335 return 0;
336
337 /* process a skip request */
338 if (state->seek)
339 {
340 state->seek = 0;
341 if (gz_skip(state, state->skip) == -1)
342 return 0;
343 }
344
345 /* get len bytes to buf, or less than len if at the end */
346 got = 0;
347 do
348 {
349 /* set n to the maximum amount of len that fits in an unsigned int */
350 n = -1;
351 if (n > len)
352 n = len;
353
354 /* first just try copying data from the output buffer */
355 if (state->x.have)
356 {
357 if (state->x.have < n)
358 n = state->x.have;
359 memcpy(buf, state->x.next, n);
360 state->x.next += n;
361 state->x.have -= n;
362 }
363
364 /* output buffer empty -- return if we're at the end of the input */
365 else if (state->eof && state->strm.avail_in == 0)
366 {
367 state->past = 1; /* tried to read past end */
368 break;
369 }
370
371 /* need output data -- for small len or new stream load up our output
372 buffer */
373 else if (state->how == LOOK || n < (state->size << 1))
374 {
375 /* get more output, looking for header if required */
376 if (gz_fetch(state) == -1)
377 return 0;
378 continue; /* no progress yet -- go back to copy above */
379 /* the copy above assures that we will leave with space in the
380 output buffer, allowing at least one gzungetc() to succeed */
381 }

Callers 3

gzreadFunction · 0.85
gzfreadFunction · 0.85
gzgetcFunction · 0.85

Calls 4

gz_skipFunction · 0.85
gz_fetchFunction · 0.85
gz_loadFunction · 0.85
gz_decompFunction · 0.85

Tested by

no test coverage detected