A small, modern C++, library for reading and writing a bespoke archive file format, based on PAK. The file has a ".pak" extension and is an uncompressed single file, which comprises several individual files.
There are many forms of "PAK" files. Essentially these are uncompressed archives of files. They are frequently used in video games, such as Quake. They are attractive because they are extremely simple to load at runtime, without any decompression overhead and any file can be store in them.
The API is straight forward and all of the API calls return an std::error_code
.
First, the header file needs to be included: #include <pak-io/file-system.hxx>
Then:
auto error_code = pak::FileSystem::instance().mount("path/to/archive.pak"); if (!error_code) { std::byte const* data = nullptr; uint64_t size = 0; error_code = pak::FileSystem::instance().read("file.txt", &data, &size)) if (!error_code) { // data and size now have a pointer to the data and the size of that data, in bytes. } else { std::cout << "An error occured tried to read from the pak file. [" << error_code.message() < "]" << std::endl; } } else { std::cout << "An error occured tried to mount the pak file. [" << error_code.message() < "]" << std::endl; }
NB: Several .pak files can be mounted, but there is no guarantee of which file you get if there are naming collisions.
This library also provides Python bindings.
There are three tools here:
-
pak-make: This tool will generate a .pak file from a "specification file". It takes two parameters:
--file
A fully qualified path to a "specification file".--directory
A fully qualified path to a directory to store the generated file.
The "specification file" is an extremely simple JSON file with a format of
{ "files" : [ ] }
where each entry in
files
is a string either of a fully-qualified path or a path relative to the JSON file. -
pak-unmake: This tool will extract a .pak file. It takes two parameters:
--file
A fully qualified path to an existing .pak file.--directory
A fully qualified path to a directory to store the extracted files.
-
pak-viewer: This GUI will show the contents of a particular .pak file.