using zlib

Started by
5 comments, last by fiskbil 19 years, 5 months ago
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.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
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]

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

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.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
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*)
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"
zlib has been discussed in the forum many many times. Try the forum search located in the top right hand of the page. It's pretty useful!

gl hf
I find zziplib very handy, it wraps zlib into easy to use (although C-ish) calls. It can be found here.

This topic is closed to new replies.

Advertisement