Mail Archives: djgpp/1998/02/17/17:16:59
Jaster writes:
>What I meant was.. how can I use the pack_file functions to do a type
>of export function. Say I had 3 pictures stored in a individually
>compressed datafile, how would I use the pack_file functions to read
>in each picture and then export it out to it's original uncompressed
>state..
You can do this very easily with any of the Allegro file manipulation
routines, because datafile objects can be read exactly like any other
disk file. For example you could use the pack utility with a command
like "pack u demo\demo.dat#title_text foobar.txt". If you look at the
source for the pack program you will see that it doesn't do anything
special to support this functionality, but just reads from one file and
writes into the other...
If you want to unpack each object individually, try something like:
PACKFILE *f = pack_fopen("myfile.dat#object_name", F_READ);
pack_fread(..., f);
// write data out to wherever you like
pack_fclose(f);
There is no way to obtain a directory listing for the datafile with this
method, so you must already know the name of each object. If you do need
to scan through it to find the object names, the file format is
described in grabber.txt.
Alternatively you could load the entire thing into memory by calling
load_datafile(), after which you can scan through the array of objects
to get information about each one (the list is terminated by a marker
object of type DAT_END). Use the get_datafile_property() function to
retrieve the DAT_NAME value for each object, and unless you stripped out
the grabber information, the DAT_ID('O','R','I','G') property will
contain the original filename of the object. As long as these are all
binary objects rather than any of the special Allegro types, the dat
field will point to the object data and the size field will tell you how
large it is, so you can easily write this out to a new file of your own.
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa
- Raw text -