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.
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:
- Navigate to the project root directory.
- Create a build directory: mkdir build && cd build
- Run CMake to generate the build files: cmake ..
- Build the project: cmake –build .
Example Usage
Creating an archive and adding files
int main() {
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)
GPAK_API int gpak_add_file(gpak_t *_pak, const char *_external_path, const char *_internal_path)
GPAK_API int gpak_close(gpak_t *_pak)
GPAK_API void gpak_set_compression_level(gpak_t *_pak, int _level)
@ GPAK_HEADER_COMPRESSION_ZST
Opening an archive and reading a file
int main() {
if (file) {
char buffer[256];
printf("%s", buffer);
}
}
return 0;
}
GPAK_API long gpak_feof(gpak_file_t *_file)
GPAK_API gpak_t * gpak_open(const char *_path, int _mode)
GPAK_API char * gpak_fgets(gpak_file_t *_file, char *_buffer, int _max)
GPAK_API gpak_file_t * gpak_fopen(gpak_t *_pak, const char *_path)
GPAK_API void gpak_fclose(gpak_file_t *_file)
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.