Xceed Zip Compression Library Documentation
Unzipping files from a zip file directly to memory
Getting started quickly > Unzipping files from a zip file directly to memory

Decompressing from a zip file directly to memory

When unzipping files, Xceed Zip allows you selectively determine the way it will be unzipped. You can chose to unzip files to disk (the default), to unzip files into a single block of memory, or to provide you with streaming data (blocks of uncompressed data as it becomes available from the decompression engine). To unzip files to memory, perform the following 6 steps.

Here is sample code for these 6 steps (excluding the code for the UnzippingMemoryFile event): 

Visual Basic Copy Code

' Don't forget to put an Xceed Zip control on a form
Dim ResultCode As xcdError

Call XceedZip1.License( "your license key" )
XceedZip1.ZipFilename = "c:\incoming\searchresults.zip"
XceedZip1.UnzipToFolder = "c:\other files\"

ResultCode = XceedZip1.Unzip

If ResultCode = xerSuccess Then MsgBox "Files unzipped successfully." Then
Else
   MsgBox XceedZip1.GetErrorDescription(xvtError, ResultCode)
EndIf

Delphi Copy Code

var xErr : xcdError; 
begin
   XceedZip1.License( 'your license key' );
   XceedZip1.ZipFilename := 'c:\incoming\searchresults.zip'; 
   XceedZip1.UnzipToFolder := 'c:\other files';  

   xErr := XceedZip1.Unzip; 
   ShowMessage( XceedZip1.GetErrorDescription( xvtError, xErr ) ); 
end;

Here is sample code to put into the UnzipPreprocessingFile event handler. This sample assumes you only want two particular files to be unzipped to memory, and the rest to go to "c:\other files":
Visual Basic Copy Code
If sFilename = "results.txt" Or sFilename = "query.txt" Then
  xDestination = xudMemory
End If
Delphi Copy Code
if( sFilename = 'results.txt' ) or ( sFilename = 'query.txt' ) then
  xDestination := xudMemory;
Here is sample code to put into the UnzippingMemoryFile event handler. This sample assumes you have declared the "results" and "query" variables globally elsewhere than in the UnzippingMemoryFile event handler:
Visual Basic Copy Code

Dim Results As String -- move this line to declare variable globally
Dim Query As String -- move this line to declare variable globally

If sFilename = "results.txt" Then
  Results = baData
ElseIf sFilename = "query.txt" T
hen
  Query = baData
End If

XAML Copy Code

var

   sResult : string; { move this line to declare variable globally } 
   sQuery : string; { move this line to declare variable globally } 
   lSize : LongInt; 
   pData : PChar; 

begin
   { the file does not contain the null-terminating char } 
   lSize := VarArrayHighBound( vaUncompressedData, 1 ) - VarArrayLowBound( vaUncompressedData, 1 ) + 1; 

   GetMem( pData, lSize + 1 ); 
   CopyMemory( pData, VarArrayLock( vaUncompressedData ), lSize ); 
   VarArrayUnlock( vaUncompressedData ); 

   pData[ lSize ] := #0;  

   if ( sFilename = 'results.txt' ) then 
   begin 
      sResult := pData; 
      ListBox1.Items.Add( sResult ); 
   end;  

   if ( sFilename = 'query.txt' ) then 
     sQuery := pData; 
end;