#include <cafe/zipfile.h>

typedef void * (*ZIPFILE_pf_Alloc)(size_t aBytes);
typedef void   (*ZIPFILE_pf_Free)(void *addr);

    struct _ZIPPED_DIR * mpParentDir;
    char const *         mpNameOnly;
    u32                  mNameOnlyLen;
    u8 const *           mpCompData;
    u32                  mCompBytes;
    u32                  mUncompBytes;
    u32                  mUncompCRC;
typedef struct _ZIPPED_FILE ZIPPED_FILE;

struct _ZIPPED_DIR
    struct _ZIPPED_DIR *    mpParentDir;
    char const *            mpNameOnly;
    u32                     mNameOnlyLen;
    u32                     mNumFiles;
    ZIPPED_FILE *           mpFilesArray;
    struct _ZIPPED_DIR *    mpSubDirList;
    struct _ZIPPED_DIR *    mpNextSib;
typedef struct _ZIPPED_DIR ZIPPED_DIR;

int ZIPFILE_CreateDir(
        u8 const *          apFileData, 
        u32                 aFileBytes, 
        ZIPFILE_pf_Alloc    afAlloc, 
        ZIPFILE_pf_Free     afFree, 
        ZIPPED_DIR **       appRetDir


apFileData Pointer to byte array of the entire ZIP file to be parsed.
aFileBytes Number of bytes in the ZIP file pointed to by apFileData argument.
afAlloc Pointer to function to use to allocate memory.
afFree Pointer to function to use to deallocated memory allocated with the function pointed to by the afAlloc argument.
appRetDir Pointer to pointer to receive address of the beginning of the memory block allocated for the manifest. This is also the pointer to the root directory of the ZIP file.

Return Values

Returns zero for success or an error code to indicate failure. Error codes are:

ERRCODE_ZIPFILE_INVALID_FILEENTRYA file entry in the input ZIP file was not valid
ERRCODE_ZIPFILE_INVALID_CDSThe Central Directory structure of the ZIP was not valid.
ERRCODE_ZIPFILE_INVALID_CDSTAILThe Central Directory Tail structure of the ZIP was not valid.
ERRCODE_ZIPFILE_INVALID_BAD_FILESIZEThe compressed size of a file in the ZIP was not valid
ERRCODE_ZIPFILE_INVALID_NO_FILE_ENTRIESThere are no file or directory entries in the ZIP file.
ERRCODE_ZIPFILE_INVALID_UNEXPECTED_EOFUnexpected end-of-file was encountered while parsing.
ERRCODE_ZIPFILE_INVALID_NO_CDSThere is no Central Directory in the ZIP file.
ERRCODE_ZIPFILE_INVALID_NO_CDS_TAILThere is no Central Directory Tail in the ZIP file.
ERRCODE_ZIPFILE_INVALID_JUNK_AT_EOFThere is some garbage left after the ZIP file data.
ERRCODE_ZIPFILE_INVALID_BAD_FILE_COUNTThe files in the ZIP and the Central Directory do not match
ERRCODE_ZIPFILE_EMPTYThere are no files with data in them in the ZIP file
ERRCODE_ZIPFILE_OUTOFMEMORYThe allocator function returned NULL
ERRCODE_ZIPFILE_ARGAnd argument passed to the function was not valid.


This library provides facilities for parsing a ZIP file so that files in the ZIP can be easily found and extracted. ZIP files are in little-endian format and this library parses a manifest into target byte order (big-endian), so that files can be easily found and extracted.

Demonstration of use in Cafe

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


Do Not Call From

Multiple threads This function is not thread-safe.

See Also

ZIPFILE helper library and demo
zlib Overview

Revision History

2011/10/19 Added Examplemake.
2011/03/11 Initial version.