Page 1 of 1

Algorithm for packing files into archive and fast access

Posted: Wed Nov 14, 2012 5:51 am
by finale00
What's a fast way to pack together a bunch of files with a reasonably fast way to index them?

Code: Select all

File Table
File Data
I can build the table and the data separately, like for each file, create an entry for the file, and put the file data in a buffer. Then, combine the table and data sections together and then increment all offsets in the table to the start of the data sections.

Or perhaps...

Code: Select all

entry_header 1
entry_data 1
entry_header 2
entry_data 2
...
Which means I don't have to worry about keeping track of my data I just need to write as I go.
Except I guess the problem is that if you want to find a file you need to loop through every entry...

Re: Algorithm for packing files into archive and fast access

Posted: Fri Nov 16, 2012 7:02 pm
by Sir Kane
Save file data at the start end the table at the end. Then maybe put CRC32 or some other hash values in the table and sort it by them. Then to locate a file, you hash the passed filename and do a binary search for it. Also need to normalize the path before hashing, so you get the correct hash.