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

Function gz_read

freebsd/contrib/zstd/zlibWrapper/gzread.c:306–384  ·  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.state->err must be consulted in that case to determine which. */

(state, buf, len)

Source from the content-addressed store, hash-verified

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

Callers 3

gzreadFunction · 0.70
gzfreadFunction · 0.70
gzgetcFunction · 0.70

Calls 5

gz_skipFunction · 0.70
gz_fetchFunction · 0.70
gz_loadFunction · 0.70
gz_decompFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected