Unzipping files from a zip file directly to memory
In This Topic
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.
Specify the zip file to unzip files from. To do this, set the ZipFilename property.
Specify the folder where to unzip files to (even if you are unzipping all files to memory). To do this, set UnzipToFolder property.
Tell Xceed Zip to start unzipping. To do this, call the Unzip method.
Tell Xceed Zip which files you want it to unzip directly to memory. To do this, write a handler for the UnzipPreprocessingFile event.
Get the uncompressed file data. To do this, write a handler for the UnzippingMemoryFile event.
Make sure it worked successfully. To do this, check the Unzip method's return value.
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
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" Then 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;