Original Post
I am working on a graphical filetype, and in a seperate program I can create it and compress it with zlib. I am working on the C++ functions to acess it, but am hung up on zlib. Basically what I am doing is loading the header and decompressing it, then memcpy'ing it onto a struct. But I get absolutly no results. Here is the relevant code: Any help from someone who has wrassled with zlib before would be very appreciated.
int ret;
FILE *fp=fopen(filename, "rb");
if(fp == NULL)
return FIM_NULL_FILEHANDLE;
int fileSize;
fseek(fp, 0, SEEK_END);
fileSize = ftell(fp);
fileSize /= sizeof(ANIMATION);
fseek(fp, 0, SEEK_SET);
FIM_BYTE headerBuffer[sizeof(FIMHEADER)];
FIM_BYTE headerIn[sizeof(FIMHEADER)];
file->z.zalloc = Z_NULL;
file->z.zfree = Z_NULL;
file->z.opaque = Z_NULL;
file->z.avail_in = 0;
file->z.next_in = Z_NULL;
ret = inflateInit(&file->z);
do
{
file->z.avail_in = fread(headerIn, 1, sizeof(FIMHEADER), fp);
if(file->z.avail_in == 0)
break;
file->z.next_in = headerIn;
do
{
file->z.avail_out = sizeof(FIMHEADER);
file->z.next_out = &file->header;
ret = inflate(&file->z, Z_NO_FLUSH);
switch (ret)
{
case Z_NEED_DICT:
ret = Z_DATA_ERROR; //fall through
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&file->z);
return ret;
}
} while (file->z.avail_out == 0);
} while(ret != Z_STREAM_END);
(void)inflateEnd(&file->z);
memcpy(&file->header, headerBuffer, sizeof(FIMHEADER));