Contents - Index - Previous - Next


UnZipToBuffer method

 

Applies to

TVCLUnZip component

 

Declaration

function UnZipToBuffer(var Buffer: PChar; FName: string): Integer;

 

Description

The UnZipToBuffer method unzips the file specified by FName parameter from the zip file specified by the ZipName property directly to the memory buffer specified by Buffer pointer parameter.  The length of the buffer is expected to be able to handle the length of the file being unzipped which can be determined by the UnCompressedSize Property.  

 

If you pass in Buffer with a value of nil then Buffer will be allocated at exactly the size of the uncompressed file by VCLUnZip and passed back to you.  It will then be your responsibility to free that memory using a call to FreeMem. 

 

Return Value  

The return value will be 1 if the buffer was extracted and 0 if it was not successfully unzipped.  

Buffered output (using a smaller buffer than the total size of the uncompressed file) is possible by setting the BufferLength property to the size of your buffer, or the amount of output that you want VCLZip to process at a time.  By setting BufferLength, the OnGetNextBuffer Event will be called after each BufferLength bytes have been unzipped. 

 

As an example, the following shows how to unzip directly into a String and attach it to a TMemo component as its text:  

 

n := FileDialog.FileBox.ItemIndex; /* Get the index of the file to unzip */ 

SetLength(Buffer, Zipper.UnCompressedSize[n]); /* Set the length of the string */ 

BufPtr := @Buffer[1] /* Point a PChar at the first character of the string */; 

Zipper.UnZipToBuffer(BufPtr, CurrentFile ); /* Unzip into the string */ 

TextMemo.Lines.Text := Buffer; /* Use that string as the TMemo's text */