Compress-Stream-Zstd
view release on metacpan or search on metacpan
ext/zstd/zlibWrapper/gzread.c view on Meta::CPAN
/* process a skip request */
if (state.state->seek) {
state.state->seek = 0;
if (gz_skip(state, state.state->skip) == -1)
return NULL;
}
/* copy output bytes up to new line or len - 1, whichever comes first --
append a terminating zero to the string (we don't check for a zero in
the contents, let the user worry about that) */
str = buf;
left = (unsigned)len - 1;
if (left) do {
/* assure that something is in the output buffer */
if (state.state->x.have == 0 && gz_fetch(state) == -1)
return NULL; /* error */
if (state.state->x.have == 0) { /* end of file */
state.state->past = 1; /* read past end */
break; /* return what we have */
}
/* look for end-of-line in current output buffer */
n = state.state->x.have > left ? left : state.state->x.have;
eol = (unsigned char *)memchr(state.state->x.next, '\n', n);
if (eol != NULL)
n = (unsigned)(eol - state.state->x.next) + 1;
/* copy through end-of-line, or remainder if not found */
memcpy(buf, state.state->x.next, n);
state.state->x.have -= n;
state.state->x.next += n;
state.state->x.pos += n;
left -= n;
buf += n;
} while (left && eol == NULL);
/* return terminated string, or if nothing, end of file */
if (buf == str)
return NULL;
buf[0] = 0;
return str;
}
/* -- see zlib.h -- */
int ZEXPORT gzdirect(file)
gzFile file;
{
gz_statep state;
/* get internal structure */
if (file == NULL)
return 0;
state.file = file;
/* if the state is not known, but we can find out, then do so (this is
mainly for right after a gzopen() or gzdopen()) */
if (state.state->mode == GZ_READ && state.state->how == LOOK && state.state->x.have == 0)
(void)gz_look(state);
/* return 1 if transparent, 0 if processing a gzip stream */
return state.state->direct;
}
/* -- see zlib.h -- */
int ZEXPORT gzclose_r(file)
gzFile file;
{
int ret, err;
gz_statep state;
/* get internal structure */
if (file == NULL)
return Z_STREAM_ERROR;
state.file = file;
/* check that we're reading */
if (state.state->mode != GZ_READ)
return Z_STREAM_ERROR;
/* free memory and close file */
if (state.state->size) {
inflateEnd(&(state.state->strm));
free(state.state->out);
free(state.state->in);
}
err = state.state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK;
gz_error(state, Z_OK, NULL);
free(state.state->path);
ret = close(state.state->fd);
free(state.state);
return ret ? Z_ERRNO : err;
}
( run in 1.094 second using v1.01-cache-2.11-cpan-39bf76dae61 )