GPAK  1.0.0
A general-purpose archive library
GPAK - Game Pack Archive Library

GPAK is a C library for creating, reading, and manipulating game archive files. It provides an API for working with game assets, making it easy to manage large collections of files within a game project.

CMake Build

Features

  • Supports multiple compression algorithms (None, Deflate, LZ4, ZSTD)
  • Easy-to-use API for creating, opening, and modifying archives
  • Stream-based file access for efficient memory usage
  • CLI tool for packing and unpacking archives

Building the Project

The project uses CMake as the build system. To build the library and all subprojects, follow these steps:

  1. Navigate to the project root directory.
  2. Create a build directory: mkdir build && cd build
  3. Run CMake to generate the build files: cmake ..
  4. Build the project: cmake –build .

Example Usage

Creating an archive and adding files

#include "gpak.h"
int main() {
gpak_t *pak = gpak_create("example.gpak", GPAK_MODE_CREATE);
gpak_add_file(pak, "external/path/to/file/file1.txt", "internal/path/to/file/file1.txt");
gpak_add_file(pak, "external/path/to/file/file2.txt", "internal/path/to/file/file2.txt");
return 0;
}
GPAK_API void gpak_set_compression_algorithm(gpak_t *_pak, int _algorithm)
Definition: gpak.c:338
GPAK_API int gpak_add_file(gpak_t *_pak, const char *_external_path, const char *_internal_path)
Definition: gpak.c:354
GPAK_API int gpak_close(gpak_t *_pak)
Definition: gpak.c:290
GPAK_API void gpak_set_compression_level(gpak_t *_pak, int _level)
Definition: gpak.c:343
@ GPAK_HEADER_COMPRESSION_ZST
Definition: gpak_data.h:36
@ GPAK_MODE_CREATE
Definition: gpak_data.h:207

Opening an archive and reading a file

#include "gpak.h"
int main() {
gpak_t *pak = gpak_open("example.gpak", GPAK_MODE_READ_ONLY);
gpak_file_t *file = gpak_fopen(pak, "file1.txt");
if (file) {
char buffer[256];
while (!gpak_feof(file)) {
gpak_fgets(file, buffer, sizeof(buffer));
printf("%s", buffer);
}
}
return 0;
}
GPAK_API long gpak_feof(gpak_file_t *_file)
Definition: gpak.c:465
GPAK_API gpak_t * gpak_open(const char *_path, int _mode)
Definition: gpak.c:213
GPAK_API char * gpak_fgets(gpak_file_t *_file, char *_buffer, int _max)
Definition: gpak.c:440
GPAK_API gpak_file_t * gpak_fopen(gpak_t *_pak, const char *_path)
Definition: gpak.c:389
GPAK_API void gpak_fclose(gpak_file_t *_file)
Definition: gpak.c:470
@ GPAK_MODE_READ_ONLY
Definition: gpak_data.h:208

Documentation

You can find documentation here https://adamfull.github.io/pak_archive/

Packer Tool

A command-line interface (CLI) tool for packing and unpacking GPAK archives is included in the packer_tool directory. After building the project, the tool can be found in the build directory as packer_tool.

Usage

  • To pack an archive: ./packer_tool -pack -src input_directory -dst output.gpak -alg zst -lvl 22
  • To unpack an archive: ./packer_tool -unpack -src output.gpak -dst output_directory

Options

  • -pack: Run packer_tool in packing mode to create a new archive.
  • -unpack: Run packer_tool in unpacking mode to extract the contents of an existing archive.
  • -src: Path to the source file or directory, depending on the mode.
  • -dst: Path to the destination file or directory, depending on the mode.
  • -alg: Choose the compression algorithm: deflate, lz4, or zst.
  • -lvl: Choose the compression level. For deflate, the maximum level is 9. For lz4, the maximum level is 12. For zst, the maximum level is 22.

License

This project is licensed under the MIT License.