This topic demonstrates how to handle multiple files in a GZip archive: listing its contents and adding an item.
Although Xceed’s implementation of GZip allows you to read and create multi-file GZip archives, it is not recommended to store multiple files in a GZip archive, for two reasons. First, most popular archiving applications do not fully support multi-file GZip archives. Second, GZip archives possess no central header to indicate where each compressed file is stored, so when you extract a specific file from a GZip archive, each GZipped file preceding that file must first be decompressed. As a result, multi-file GZip archives can be very inefficient. It is strongly recommended that you combine the compression capabilities of GZip with the archiving capabilities of Tar instead. See the topics in the Xceed Tar book for details.
To handle multi-file GZip archives, set the static boolean property AllowMultipleFiles of the GZipArchive class to true. By default, this property is set to false. If you attempt to create a multi-file GZip archive when this property is set to false, an exception will be thrown. If you attempt to read a multi-file GZip archive when this property is false, only the first file will be read.
FileSystem-based GZip is not currently available in Xceed's .NET Compact Framework products.
Basic steps
To list the contents of a multi-file GZip archive, the following steps must be performed:
-
Set the static AllowMultipleFiles property to true. If you do not do this, only the first file will be read. Note also that you must do this before retrieving the GZipArchive reference.
-
Retrieve a reference to a GZip archive using the GZipArchive class.
-
Call the GetFiles method to retrieve a listing of the files contained within the GZip archive.
-
You can now loop through the files and extract the desired information.
To create a multi-file GZip archive, the following steps must be performed:
-
Set the static AllowMultipleFiles property to true.
-
Retrieve a reference to a GZip archive using the GZipArchive class.
-
Retrieve a reference to a source using an AbstractFolder-derived class.
-
Call the CopyFilesTo method on the source, passing the destination GZip archive.
Demonstration
This example demonstrates how to list the contents of a multi-file GZip archive.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
This example demonstrates how to create a multi-file GZip archive.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
Things you should consider
The main questions you should ask yourself when performing these operations with a GZip archive are: