Skip to content
modkitv0.2

zip.h

#include <modkit/zip.h>11 functions · 1 typedefs

ZIP archive reading for texture packs and asset bundles.

Provides simple API for reading files from ZIP archives, designed for loading Polyhaven-style texture packs (GLTF + textures). Usage:

Functions

mk_zip_closefunction

void mk_zip_close(mk_zip_t *zip)

Close a ZIP archive.

ParameterTypeDescription
zipmk_zip_t *Value for zip.

mk_zip_existsfunction

bool mk_zip_exists(mk_zip_t *zip, const char *name)

Check if a file exists in the archive.

ParameterTypeDescription
zipmk_zip_t *Archive handle
nameconst char *File path within the archive

Returns true if file exists

mk_zip_file_countfunction

int mk_zip_file_count(mk_zip_t *zip)

Get the number of files in the archive.

ParameterTypeDescription
zipmk_zip_t *Value for zip.

Returns The resulting value.

mk_zip_file_namefunction

const char * mk_zip_file_name(mk_zip_t *zip, int index)

Get the name of a file by index.

ParameterTypeDescription
zipmk_zip_t *Archive handle
indexintFile index (0 to file_count-1)

Returns File name, or NULL if index is out of range

mk_zip_file_sizefunction

size_t mk_zip_file_size(mk_zip_t *zip, const char *name)

Get the uncompressed size of a file.

ParameterTypeDescription
zipmk_zip_t *Archive handle
nameconst char *File path within the archive

Returns Size in bytes, or 0 if file not found

mk_zip_findfunction

int mk_zip_find(mk_zip_t *zip, const char *pattern, const char **out_names, int max_names)

Find files matching a pattern (glob-style).

Patterns support * (any characters) and ? (single character).

ParameterTypeDescription
zipmk_zip_t *Archive handle
patternconst char *Glob pattern, for example textures/(wildcard).jpg
out_namesconst char **Array to receive file names (can be NULL to just count)
max_namesintMaximum number of names to return

Returns Number of matching files

mk_zip_freefunction

void mk_zip_free(void *data)

Free memory allocated by mk_zip_read().

ParameterTypeDescription
datavoid *Data buffer.

mk_zip_openfunction

mk_zip_t * mk_zip_open(const char *path)

Open a ZIP archive for reading.

ParameterTypeDescription
pathconst char *Path to the ZIP file

Returns Handle to the archive, or NULL on failure

mk_zip_open_memfunction

mk_zip_t * mk_zip_open_mem(const void *data, size_t size)

Open a ZIP archive from memory.

ParameterTypeDescription
dataconst void *Pointer to ZIP data in memory
sizesize_tSize of the data in bytes

Returns Handle to the archive, or NULL on failure

mk_zip_readfunction

void * mk_zip_read(mk_zip_t *zip, const char *name, size_t *out_size)

Read a file from the archive.

ParameterTypeDescription
zipmk_zip_t *Archive handle
nameconst char *File path within the archive
out_sizesize_t *Pointer to receive the size of the data (can be NULL)

Returns Allocated buffer with file contents, or NULL on failure

mk_zip_read_intofunction

int mk_zip_read_into(mk_zip_t *zip, const char *name, void *buf, size_t buf_size)

Read a file from the archive into an existing buffer.

ParameterTypeDescription
zipmk_zip_t *Archive handle
nameconst char *File path within the archive
bufvoid *Buffer to read into
buf_sizesize_tSize of the buffer

Returns Number of bytes read, or -1 on failure

Typedefs

mk_zip_ttypedef

typedef struct mk_zip mk_zip_t

Type used for zip.