zlib and zip



I have a zip file created with the zip command on Linux. Now I'm writing a
decompressor using zlib.

The zip file is not corrupted (unzip has no problems with it), and the
compressed files all report themselves as deflate compressed. I have read
all the meta data from the zip file, which all seems to be correct, and now
I'm trying to decompress the actual files.

The local entry header says the compressed data starts at some offset from
the beginning of the local entry header, so I am seeking to the start of
the local entry header plus that offset (measured from the beginning of the
zip file), then reading the entire compressed data specified in the local
entry header. I am then using this sequence of zlib functions (minus error
handling for brevity):

z_stream zip;

....read compressed data from zip file...

zip.zalloc = Z_NULL;
zip.zfree = Z_NULL;
zip.opaque = Z_NULL;
zip.next_in = Z_NULL;
zip.avail_in = 0;

inflateInit2(&zip,-MAX_WBITS);
zip.next_in = (Bytef *)caInput
zip.next_out = (Bytef *)caBuffer;
zip.avail_out = nSizeUncompressed + 1;
zip.avail_in = nSizeCompressed;
nError = inflate(&zip,Z_STREAM_END);

At this point, nError is -3 (Z_DATA_ERROR).

caInput is a (char *) array that contains the total number of compressed
bytes specified in the local entry header, starting at header+offset from
the start of the zip file.

caBuffer is a (char *) array equal in size to the full decompressed data as
specified inthe local entry header plus one byte to satisfy zlib
requirements.

nSizeUncompressed and nSizeCompressed are the sizes of the uncompressed and
compressed data respectively, as specified in the local entry header.

1) Am I seeking to the correct place?
2) Am I using zlib correctly?

.