ZIPFILE Helper Library and Demo

Usage in Your Program

#include <cafe/zipfile.h>

The ZIPFILE library is provided as a helper tool. It parses ZIP files based on the publicly available information about the ZIP file format.

How it Works

Create a ZIP file on Windows by right-clicking on selection of files or a folder and selecting "Send To → Compressed (Zipped) Folder".

The main library function is

int ZIPFILE_CreateDir(
    UINT8 const *       apFileData, 
    UINT32              aFileBytes, 
    ZIPFILE_pf_Alloc    afAlloc, 
    ZIPFILE_pf_Free     afFree, 
    ZIPPED_DIR **       appRetDir);

It takes as input a blob of memory that is the compressed ZIP file, which has been placed into memory in its entirety by some mechanism (built in, loaded, etc). This library does not do the loading.

The function parses the file and creates a manifest that looks like a folder tree. The manifest has pointers in it that refer to data in the original input blob. A pointer to the root folder is returned by the function as an output parameter.

The library function uses allocate/free functions you provide to allocate a single contiguous blob of memory for the manifest. The manifest contains the ZIPPED_DIR and ZIPPED_FILE structures that refer to each other. The structures are in target system byte order and can be used directly.

When you are finished with the manifest, free the memory associated with it by using a single call to your free function with the pointer to the root directory as an argument.

Demonstration of Use in Cafe

There is a demonstration of usage of the helper library in the demo folder:


Revision History

2012/01/30 Initial version.