Archived

This topic is now archived and is closed to further replies.

cody

zlib for reading zip files?

Recommended Posts

im using zip files to store data for my game. it can only read uncompressed zips because i dont know how to use zlib to uncompress the data. i can however read the compressed data out of the archive. but when i try to decode the data with zlib´s inflate there is an error after zlib has read the first byte. what am i doing wrong? cant zlib decompress data from winzip? or am i using the inflate function wrong? i have searched on this forum for this answer but unsuccessful...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
try this:
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-ZipLoad&forum=cotd&id=-1

Share this post


Link to post
Share on other sites
oh i think i called the function wrong because i dont have this zlib header that is mentioned here:

(from your url)

stream.next_in = (Bytef*)pcData;
stream.avail_in = (uInt)h.cSize;
stream.next_out = (Bytef*)pBuf;
stream.avail_out = h.ucSize;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;

// Perform inflation. wbits < 0 indicates no zlib header inside the data.
err = inflateInit2(&stream, -MAX_WBITS);


i will try that now, thankyou.

btw: how is this code-tag in this forum?

[edited by - cody on August 16, 2002 3:14:54 PM]

[edited by - cody on August 16, 2002 3:16:51 PM]

Share this post


Link to post
Share on other sites
As of version 1.1.4, ZLIB distribution includes the zip and
unzip library for easily creating and extracting files in
the ZIP archive format. I use them myself and they''re almost
too easy to use. Check here for more info.

Maybe you feel like writing the zip/unzip functions using
the low-level deflate/inflate interface. I don''t know.



Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
yeah i cant use these functions because zip file reading is already implemented with a virtual file system, but without compression though...


[edited by - cody on August 16, 2002 3:19:23 PM]

Share this post


Link to post
Share on other sites
It sure beats writing them myself (reinventing the wheel?).
I use libpng and libjpeg by providing my own I/O functions
as well. *shrug*.



Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites
yeah i use these libs too.
but using zlib was already planed to be used just for decompression. the archive reader was ready long time before.
and the jpeg or png formats are much more complex than zip.
maybe i would use the functions you suggested if i would rewrite everything, but now its like this: when i only use the zlib inflate functions i have to change 5 lines of code, otherwise ~50.

now it works alright!

Share this post


Link to post
Share on other sites