Contents - Index - Previous - Next


BufferLength property

 

Applies to

TVCLUnZip component

 

Declaration

property BufferLength: LongInt;

 

Description

Setting BufferLength to some value greater than zero, allows buffered output when unzipping directly to memory. Setting this property before calling either of the UnZipToBuffer methods...  

 

UnZipToBuffer 

UnZipToBufferByIndex 

 

to some value less than the total uncompressed size of the file being extracted will cause the OnGetNextBuffer Event event to be called every time BufferLength bytes have been unzipped. 

 

This can be useful also if you wish to preview what is in a large file without unzipping the entire file.  Or if you wish to be able to see a large file in an editor before the entire file is opened up into it.  

As an example, the following will unzip a file into a string buffer.  BufferLength is set to 1/4th of the length of the string buffer in order to show how OnGetNextBuffer gets called:

  

var 

sBuffer, CurrentFile: String; 

tempPointer: pChar; 

n: Integer; 

begin 

    n := FileDialog.FileBox.ItemIndex;     /* Get index number of file to be unzipped */ 

CurrentFile := LowerCase(FileDialog.SelectedFile.Text); /* Get the filename to be unzipped */ 

SetLength(sBuffer, Zipper.UnCompressedSize[n]); /* Set string length to uncompressed size of the file */ 

tempPointer := @sBuffer[1]; /* PChar pointer to begining of string */ 

Zipper.BufferLength := Length(sBuffer) div 4; /* Set the BufferLength */ 

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

TextMemo.Lines.Text := sBuffer; /* Point a textmemo at it so you can see it */ 

end; 

  

/* The OnGetNextBuffer event */ 

procedure TForm1.ZipperGetNextBuffer(Sender: TObject; var Buffer: PChar; FName: String; AmountUsed, BufferNum: Integer; var Quit: Boolean); 

begin 

Buffer := Buffer + AmountUsed;  /* Slide the buffer pointer to the end of what has already been unzipped /* 

end; 

 

Notice how the buffer pointer is slid along the string so that the next output from VCLZip will be appended to the end of what has already been unzipped.  You can also leave the pointer at the same position if you wish to use the same buffer over and over again.  You might use this technique if you simply copy the output from the buffer each time the OnGetNextBuffer event is called.  

 

Run-time only