[vox-tech] archiving library in C
Bill Broadley
vox-tech@lists.lugod.org
Sun, 2 Feb 2003 22:55:00 -0800
Hrm, seems like tar is overkill. I'd suggest just designing your
own file format. A few tips:
Include a version number in the file.
Include a few bytes so you can check endianess. (I.e. big or little)
Use offsets stored at the beginning of the file
Include the total length
Include a special tag between filetypes
Something like:
<version>
<endianess test>
<filename><start of file><length
<filename><start of file><length
<filename><start of file><length
<filename><start of file><length
<filename><start of file><length
<end of index/directory>
<begin of file>
<end of file>
<begin of file>
<end of file>
....
<end of data>
<EOF>
I.e.:
V0.1 Bill File Format<CR>
1234<CR>
foo.mp3 64 125000<CR>
foo.jpg 125064 25000
foo.dat 150064 1024
<foo.mp3>start
data data data data
<foo.mp3>stop
<foo.jpg>start
data data data data
<foo.jpg>stop
<foo.dat>start
data data data data
<foo.dat>stop
<EOD>
<EOF>
That way you just write a input routing called get_index(char *ptr)
and it will return the index you can fseek to, then you just use the normal
fread and fwrite until you hit the length of the file.
This gives you quite a few advantages:
Will work on alpha, sun, intel, and other cpus
Light weight
Redundant data aiding in recovery from corrupted files
ease of implementation.
Endusers will not be able to tar xvf gamedata.dat then complain that
the game doesn't work.
On Sat, Feb 01, 2003 at 03:47:59PM -0800, Peter Jay Salzman wrote:
> hi all,
>
> suppose i have a video file, a sound file, an image file, a gnumeric
> spreadsheet, a number, a boolean and an mp3.
>
> and suppose all those things are needed by a C program. kind of like
> how a game uses a plethora of image and sound files.
>
> is there a library that will allow me to combine all that different
> stuff into a single file and then let me transparently access any
> individual element using an API in C?
>
> i suppose i can do it with a bunch of system() calls with tar, but that
> isn't a very nice solution.
>
> i've delved into the code for lxdoom, prboom and doom legacy. wad files
> are very similar. they have a directory structure and there's an
> interface for accessing any particular element of the wad file. the
> boundary between "things" is enforced by the wad format itself, but it's
> up to the program itself (doom) to interpret the returned data correctly
> (whether it's sound info, image info, a linedef, etc....).
>
> anything similar as a canned C library? tar/ar would be perfect if
> there was a C API to go along with them.
>
> pete
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech
--
Bill Broadley
Mathematics
UC Davis