The following example demonstrates how to decompress a GZip archive that contains multiple segments that need to be concatenated into a single uncompressed destination file.
Typically, GZip is used to compress a single "stream". However, the file format allows for multiple streams to be archived in a single GZip file. These multiple streams can refer to different files but, the streams are often just segments of a single file that are meant to be concatenated into a single uncompressed file.
The GZip file format contains no field or flag that clearly indicates how the multiple streams are to be handled. Typically, they are meant to be concatenated into a single destination.
The default behavior of GZipArchive is to process the first file only and stop. This is because most GZip archives only contain one file. However, it is possible to make GZipArchive process all the segments in an archive and concatenate them into the destination file.
To enable the feature, the static property GZipArchive.AllowMultipleFiles must be set to 'true'. Then, the GZipArchive.CopyFilesTo() method is used, it takes a AbstractFile object as the destination instead of an AbstractFolder, meaning that the method will extract and concatenate all the files in the archive to the destination file.
FileSystem-based GZip is not currently available in Xceed's .NET Compact Framework products.
Steps
To extract items from a GZip archive to a single destination file, the following steps must be performed:
-
Retrieve a reference to a GZip archive using the GZipArchive class.
-
Set the GZipArchive.AllowMultipleFiles to 'true'.
-
Retrieve a reference to a file where the files will be extracted to using an AbstractFile-derived class such as DiskFile, MemoryFile, FtpFile, etc.
-
Call the CopyFilesTo method to copy the GZipped files to the destination file.
Demonstration
Things you should consider
The main questions you should ask yourself when extracting items from a GZip archive are: