delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/17/17:16:59

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Can I use allegro datafile like .zip files?
Date: Mon, 16 Feb 1998 19:30:08 +0000
Organization: None
Distribution: world
Message-ID: <dcHETKAAPJ60EwKR@talula.demon.co.uk>
References: <34e5402f DOT 18617202 AT news DOT earthlink DOT net>
<34e784ce DOT 53311912 AT news DOT earthlink DOT net>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 42
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019