Fudge Packing

posted in DruinkJournal
Published February 13, 2005
Advertisement
Well, I thought I should probably make use of this journal, considering I have it. Well, I finished making my pack library, which is nice. It has the cheerful name of Fudge Packer. Blame ravuya for the name. You can pack files using 4 types of compression; None (Ok, that doesn't really count as a level of compression), zlib (fastest compression), zlib (best compression), or bzip2.
Here's some lovely screenshots of the pack utility in action, packing some data for my bomberman clone:
zlib (fast)
zlib (best)
bzip2

Accessing data in the pack file is easy, the pack reader manages an internal buffer for you, so you can extract files into the buffer, and then just get a BYTE* to the uncompressed data. Here's some sample code:
// Create reader and open the file //IPackReader* pReader = CreateReader();if(!pReader->OpenFile("Data.pak")){   DestroyInstance(pReader);   return -1;}// Get a handle (index) to the file //DWORD dwHandle = pReader->GetFileIndex("Data/Test.txt");if(dwHandle == INVALID_PAK_HANDLE){   DestroyInstance(pReader);   return -1;}// Get it's length and extract it //DWORD dwLength = pReader->GetFileSize(dwHandle);BYTE* pTempBuff = pReader->ExtractFile(dwHandle);// Do something with the buffer here //// Cleanup //pReader->CloseFile();DestroyInstance(pReader);return 0;


Well, this'll do for now I think. If you want to play around with Fudge Packer, you can Download the dll, lib and header file and give it a go.
0 likes 3 comments

Comments

ArchWizard
FIRST COMMENT!

Seriously though, that looks pretty neat. You should write a tutorial or something.
February 13, 2005 04:13 PM
Evil Steve
I spelt 'zlib' wrong in the 2nd screenshot. Tweedledee pointed it out.
There's already An Article here on GDNet about making a pack file, although it doesn't cover compression.
The code is written in a way that makes it easy to add new compression formats, although the 4 that there are should be quite enough I think.
My pack file uses memory mapped files too, and I've extracted a 600Mb file without problems (although getting a BYTE* to it takes about 5 minutes, with the call to new[] taking 3 of those minutes - although if no compression is used, it just gives you an offset of the memory mapped file pointer for speed)
February 13, 2005 04:59 PM
Drew_Benton
This looks very intresting! I am going to have a look and let you know what I think [smile]
February 16, 2005 02:44 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement