Jump to content
  • Advertisement
Sign in to follow this  

using zlib

This topic is 4925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. Does anyone know how to use zlib to view and extract a particular file from an archive? I have taken a look at the info on the site, and it says how to decompress some data in memory, but I can't see how to look view what files are in an archive.

Share this post


Link to post
Share on other sites
Advertisement
The whole zlib isn't particularely clear, but look into the contrib folder.

If you're after PKZip (Winzip etc.) look into minizip.c/.h, it will behave like a command line zip tool and shows how to read and write a file from an archive.

There's also a file for GZip.

[edit: cleared up]

[Edited by - Endurion on November 24, 2004 3:56:49 AM]

Share this post


Link to post
Share on other sites
Okay, I've looked, but it seems that the function "file_uncompress" deletes the archive after uncompressing, so I thought to use "gz_uncompress", but what is the definition 'gzFile'.

Is it a typedef of something or an defined type such as a struct?

I've been looking, but as of yet, I haven't been able to find the definition of it.

Share this post


Link to post
Share on other sites
from the manual:

Quote:

int gzread (gzFile file, voidp buf, unsigned len);
Reads the given number of uncompressed bytes from the compressed file.

typedef voidp gzFile;


(voidp is void*)

Share this post


Link to post
Share on other sites
I hope that this will be helpful. I dont know if it works.
BTW the functions that I use here are defined in "unzip.h"


unzFile openZipFile(const char* strZipPackage, const char* strFile)
{
unzFile fp = unzOpen(strZipPackage);
if (fp == NULL) return NULL;
if (unzLocateFile(fp,strFile,0) != UNZ_OK)
{
unzClose(fp);
return NULL;
}

if (unzOpenCurrentFile(fp) != UNZ_OK)
{
unzClose(fp);
return NULL;
}

return fp;
}

void closeZipFile(unzFile fp)
{
if (fp)
{
unzCloseCurrentFile(fp);
unzClose(fp);
}
}

void printZipPackageContent(const char* strZipPackage)
{
unzFile fp = unzOpen(strZipPackage);
if (fp == 0) return;

bool more_files = true;
unzGoToFirstFile(fp);

while (more_files)
{
char strFileName[256];
unz_file_info finfo; // holds some info about the file

unzGetCurrentFileInfo(fp,&finfo,strFileName,256,NULL,0,NULL,0);
more_files = (unzGoToNextFile(fp) == UNZ_OK);

printf("%s\n",strFileName);
}
}




to read from a zip file, simply use "unzReadCurrentFile"

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!