Introduction
I developed this class because I needed a general class that will detect internally if a file is an archive, and then read the compressed files contained in the archive. For Zip and gz archives, I found the source code on CodeProject, in the articles of Hans Dietrich and Jonathan de Halleux.
I also implemented in the class the possibility of detecting & reading from tar files.
Using the code
The class provides methods for: detecting and opening an archive, returning the number of files in an archive, and reading files from archives based on file position. In the header file we have the methods and their description.
BOOL OpenArchive(IN const char* pszArchiveFile);
void CloseArchive();
int GetCompressedFilesCount();
BOOL GetArchiveFile( IN int nFileIndex,
OUT char** pszFileBuffer,
OUT int& nFileSize,
OUT BOOL& fIsFile,
OUT CString& szFileName);
CString GetErrorText();
BOOL OpenArchive(IN const char* pszArchiveFile);
How to use
Include the DecompressLibrary project in your workspace. Next include the DecompressClass.h header file. Sample usage:
CDecompressClass testObj;
testObj.OpenArchive("archivefile.zip");
for (int i=0; i < testObj.GetCompressedFilesCount(); i++)
{
char* pszFileBuffer;
int nFileLength;
CString szFileName;
BOOL fIsFile;
testObj.GetArchiveFile(i,
&pszFileBuffer,
nFileLength,
fIsFile,
szFileName
);
}
History
- Version 1.0 - 2005 Nov 14, first implementation of the class.
Demo app
You will find a test dialog used to test the class:

Usage
This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.