Sign in to follow this  
  • entries
    557
  • comments
    1237
  • views
    421604

Fudge Packing

Sign in to follow this  
Evil Steve

363 views

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.
Sign in to follow this  


3 Comments


Recommended Comments

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)

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now