Sign in to follow this  
Endar

using zlib

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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this