Board index » delphi » Save multiple files into one file

Save multiple files into one file

Hi! I would like my app to be able to save an unspecified
number of files (specifically picture files) into one single
file that could then later be parsed and separated out into
the original files. I am not worried about compressing or
encrypting the package file.

Can anybody suggest a good way to do this?

One way I thought of was with the BlockWrite proc, but since
files can be of all different sizes, I couldn't come up with
a way to keep track of the size of each individual file to
use as the "count" argument when calling BlockRead to do the
extracting.

Thanks!

Michael Jennings
jenni...@jmu.edu

 

Re:Save multiple files into one file


In article <3899d...@pigeon.jmu.edu>, "Michael S. Jennings" <jenni...@jmu.edu>
writes:

Quote
>Hi! I would like my app to be able to save an unspecified
>number of files (specifically picture files) into one single
>file that could then later be parsed and separated out into
>the original files. I am not worried about compressing or
>encrypting the package file.

>Can anybody suggest a good way to do this?

>One way I thought of was with the BlockWrite proc, but since
>files can be of all different sizes, I couldn't come up with
>a way to keep track of the size of each individual file to
>use as the "count" argument when calling BlockRead to do the
>extracting.

>Thanks!

TBitmap.SaveToStream and LoadFromStream will take care of all this for you.

So use streams. If you don't know how to use streams, with any luck Alan Lloyd
will point you to some examples:)

This has been discussed before but in brief, if they are all bitmaps it's
relatively easy. Just keep saving them by
Bitmaps[count].SaveToStream(SomeStream). To read them back just do
count:= 0;
    repeat        
      Bitmaps[count]:= TBitmap.Create;
      Bitmaps[count].LoadFromStream(SomeStream);
      inc(count);
    until stream.position = stream.size;

Something along these lines anyway. It would be wise to include some exception
handling.

Gordon.  
~~~~~~~~~~~~~~~~~~~~~~~~
Try one get one free Equation Illustrator V
http://members.aol.com/equation2/betas.htm  :))
http://members.aol.com/delphistuf/delphstf.htm   (Delphi bits and bobs and a
few links)

MGCSoft

Other Threads