# .pak file reading example (libzzip)

This topic is 4764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This isn't particularly related to game programming but is used mostly for games so I hope this is the right place to post it. I wanted to get the whole transparent .pak type file functionality working in my engine but I couldn't find anywhere with a solid example of how to do it with the libzzip library. I always find it annoying when a library doesn't have an example of how to use it (this also happens with man pages and unix commands)... but I'm ranting. So I spent some time working out how to do it, it's actually really easy but takes time reading the documentation. Anyway I came up with some example code which I hope will help other people and possibly let you know how easy it is to add this functionality to your engine. Setting out of the error handling could be done better, please post with any errors and/or modifications to the code.
#include <stdio.h>
#include <zzip/lib.h>

int main(int argc, char * const argv[])
{
// we are just going to read the first 10 characters out of the file
char* array;
array = new char[11];

// what file endings to accept... "" means that you can use /test.zip/
// in the file name - has to end with a zero
static zzip_strings_t ext[] = { ".zip", ".pak", "", 0 };

// these functions are exactly the same as the normal posix-IO ones
ZZIP_FILE * file;
// any of the directories in the path can be zip files... but they can't
// be nested. eg this opens the zipfile.zip (or .pak) file that has a directory
// called test holding the file data.dat
file = zzip_open_ext_io ("zipfile/test/data.dat", O_RDONLY, 0, ext, NULL);
if (file == NULL)
{
printf("could not open file\n");
return 1;
}
if (zzip_fread(array , sizeof(char) , 10 , file))
{
array[10] = '\0';

printf("%s\n", array);
}
else
{
}
zzip_close (file);

delete[] array;

return 0;
}


1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 17
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632148
• Total Posts
3004359

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!