Contents - Index - Previous - Next


ArchiveStream property

 

Applies to

TVCLUnZip component

 

Declaration

property ArchiveStream: TkpStream;

 

Description

This is an alternative to setting ZipName.  This property allows you to create or modify an archive an a stream other than a file.

 

The ArchiveStream property allows you to set the archive with a TStream (using D6, D7, or BCB6) or one of it's decendants, or a TkpStream (using D4, D5, BCB4, or BCB5) rather than setting the archive with a disk file using the ZipName Property.  This lets you save archives in streams like database blob streams for instance or simply use faster in memory archives providing memory to memory compression and decompression.

You should use the ArchiveStream or the ZipName property but not both when specifying the zip archive.  

If you point ArchiveStream at a stream that you create, it is important to always retrieve your stream back from ArchiveStream.  Especially if you perform multiple operations on ArchiveStream.  Otherwise your original stream will not be correct.  So always do like this

:

   ArchiveStream := myStream; // set the ArchiveStream

   VCLZip.ReadZip;  // Do this only if myStream already holds an archive

   // Perform operations

   myStream := ArchiveStream; // retrieve it back.

   ArchiveStream := nil;   // Always nil out ArchiveStream

 

For an example of Stream to Stream zipping/unzipping click here  

 

IMPORTANT: You should always free the ArhiveStream or whatever stream it points to yourself.  VCLZip will not try to free it.  You can create ArchiveStream and Free it directly such as...  

 

VCLZip1.ArchiveStream := TMemoryStream.Create; 

....  /* zip to myStream */ 

VCLZip1.ArchiveStream.Free; 

 

But more than likely you will want to use the stream afterwards. so you will probably want to retrieve the stream back from VCLZip...  

 

var myStream : TMemoryStream; 

VCLZip1.ArchiveStream := TMemoryStream.Create 

... /* zip to myStream... */ 

myStream := VCLZip.ArchiveStream;  // Get the stream for your use

VCLZip1.ArchiveStream := nil;  // detach from VCLZip.

... /* use myStream ...*/ 

myStream.Free;  // Free your stream when done

 

Setting the ArchiveStream property will also cause the KeepZipOpen Property to be set to True so that the TStream will not be Free'd in between operations.  

ArchiveStream can be a new archive (set it using a new empty stream) or it can be an existing archive.  

As an example of creating a new archive in memory using a TStream:  

 

With VCLZip1 do 

begin 

ArchiveStream := TMemoryStream.Create; /* Create archive in a memory stream */ 

FilesList.Add('c:\mydir\*.*'); /* zip all file in directory */ 

Zip; /* this zips files into an archive in ArchiveStream, a memory stream */ 

end; 

 

Remember, if you want to save the archive that you have created in the ArchiveStream, you will have to save the ArchiveStream to a file yourself.  While you are working with ArchiveStream do not also reference ZipName since a memory stream does not have a filename ofcourse. 

 

Run-time only