63 #define WINSIZE 32768U 93 off_t
in, off_t
out,
unsigned left,
unsigned char *
window)
100 if (index == NULL)
return NULL;
102 if (index->
list == NULL) {
111 else if (index->
have == index->
size) {
113 next = realloc(index->
list,
sizeof(
struct point) * index->
size);
151 unsigned char input[
CHUNK];
167 totin = totout = last = 0;
175 goto build_index_error;
179 goto build_index_error;
201 goto build_index_error;
215 (totout == 0 || totout - last > span)) {
220 goto build_index_error;
250 unsigned char *buf,
int len)
255 unsigned char input[
CHUNK];
256 unsigned char discard[
WINSIZE];
265 while (--ret && here[1].
out <= offset)
296 if (offset == 0 && skip) {
306 else if (offset != 0) {
354 int main(
int argc,
char **argv)
359 struct access *index = NULL;
360 unsigned char buf[
CHUNK];
364 fprintf(stderr,
"usage: zran file.gz\n");
367 in = fopen(argv[1],
"rb");
369 fprintf(stderr,
"zran: could not open %s for reading\n", argv[1]);
379 fprintf(stderr,
"zran: out of memory\n");
382 fprintf(stderr,
"zran: compressed data error in %s\n", argv[1]);
385 fprintf(stderr,
"zran: read error on %s\n", argv[1]);
388 fprintf(stderr,
"zran: error %d while building index\n", len);
392 fprintf(stderr,
"zran: built index with %d access points\n", len);
395 offset = (index->
list[index->
have - 1].
out << 1) / 3;
398 fprintf(stderr,
"zran: extraction failed: %s error\n",
399 len ==
Z_MEM_ERROR ?
"out of memory" :
"input corrupted");
401 fwrite(buf, 1, len, stdout);
402 fprintf(stderr,
"zran: extracted %d bytes at %llu\n", len, offset);
static int build_index(FILE *in, off_t span, struct access **built)
static void skip(file *in, unsigned n)
int main(int argc, char **argv)
#define inflateInit2(strm, windowBits)
int inflateSetDictionary(z_streamp strm, Bytef *dictionary, uInt dictLength)
int inflatePrime(z_streamp strm, int bits, int value)
static void free_index(struct access *index)
unsigned char window[32768U]
static int extract(FILE *in, struct access *index, off_t offset, unsigned char *buf, int len)
int inflateEnd(z_streamp strm)
int inflate(z_streamp strm, int flush)
static struct access * addpoint(struct access *index, int bits, off_t in, off_t out, unsigned left, unsigned char *window)