A library providing packing of files into runtime reading optimized archives, across different platforms.
For example can be used to load game resources. (images, shaders, models, levels, etc...)
See the documentation.
Features
- Compressed file pack creation
- Runtime optimized file pack reading
- Automatic file data deduplication
- Maximum ZSTD compression level
- Customisable compression threshold
- C and C++ implementations
Usage example
void packReaderExampleCPP()
{
auto itemIndex = packReader.getItemIndex("textures/sky.png");
packReader.readItemData(itemIndex, itemData);
}
Pack reader instance handle.
Definition reader.hpp:42
void packReaderExampleC()
{
if (packResult != SUCCESS_PACK_RESULT) abort();
uint64_t itemIndex = 0;
if (!result) abort();
uint8_t* itemData = (uint8_t*)malloc(dataSize);
if (!itemData) abort();
if (packResult != SUCCESS_PACK_RESULT) { free(data); abort(); }
}
uint8_t PackResult
Pack result code type.
Definition common.h:95
void destroyPackReader(PackReader packReader)
Destroys Pack reader instance.
uint32_t getPackItemDataSize(PackReader packReader, uint64_t index)
Returns Pack item uncompressed data size in bytes. (MT-Safe)
PackReader_T * PackReader
Pack reader instance.
Definition reader.h:35
PackResult readPackItemData(PackReader packReader, uint64_t itemIndex, uint8_t *buffer, uint32_t threadIndex)
Reads Pack item binary data. (MT-Safe)
PackResult createFilePackReader(const char *filePath, bool isResourcesDirectory, uint32_t threadCount, PackReader *packReader)
Creates a new file pack reader instance.
bool getPackItemIndex(PackReader packReader, const char *path, uint64_t *index)
Returns Pack item index if it is found. (MT-Safe)
Supported operating systems
- Windows (10/11)
- Ubuntu (22.04/24.04)
- macOS (14/15)
This list includes only those systems on which functionality testing is conducted. However, you can also compile it under any other Linux distribution or operating system.
Build requirements
Use building instructions to install all required tools and libraries.
CMake options
Name | Description | Default value |
PACK_BUILD_SHARED | Build Pack shared library | ON |
PACK_BUILD_UTILITIES | Build Pack utility programs | ON |
PACK_BUILD_TESTS | Build Pack library tests | ON |
CMake targets
Name | Description | Windows | macOS | Linux |
pack-static | Static Pack library | .lib | .a | .a |
pack-shared | Dynamic Pack library | .dll | .dylib | .so |
packer | Packer executable | .exe | | |
unpacker | Unpacker executable | .exe | | |
pack-info | Pack info executable | .exe | | |
Cloning
git clone --recursive https://github.com/cfnptr/pack
Building
- Windows:
./scripts/build-release.bat
- macOS / Ubuntu:
./scripts/build-release.sh
Utilities
packer
Creates compressed data pack from files.
- Usage:
packer <pack-path> <file-path-1> <item-path-1>...
- Example:
packer resources.pack C:/Users/user/Desktop/sky.png images/sky.png
unpacker
Extracts compressed data pack files.
- Usage:
unpacker <pack-path>
- Example:
unpacker resources.pack
pack-info
Shows pack file information.
- Usage:
pack-info <pack-path>
- Example:
pack-info resources.pack
Third-party
- mpio (Apache-2.0 License)
- zstd (BSD License)