zlib for reading zip files?

Started by
7 comments, last by cody 21 years, 8 months ago
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...
Advertisement
try this:
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-ZipLoad&forum=cotd&id=-1
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]
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!
神はサイコロを振らない!
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]
Well, you can provide custom file I/O to use whatever
virtual file system you''re already using.


Kami no Itte ga ore ni zettai naru!
神はサイコロを振らない!
sure, and that would be pretty ugly=)
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!
神はサイコロを振らない!
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!

This topic is closed to new replies.

Advertisement