Extract GZIP
A TGZ file, also known as a "tarball," is a file format that combines multiple files and directories into a single archive. The name "TGZ" is derived from its two main components: "TAR," which stands for "Tape Archive," and "GZ," which represents the GZIP compression used to compress the tar archive.
Below is an example of how to use the ExtractArchiveToDirectory
method of the IronGZipArchive class to extract the contents from a TGZ file. The 'output.tgz' file we created earlier is first archived using tar and then compressed with GZIP compression.
using IronGZip;
// Make sure to reference the IronGZip library in your project
class Program
{
static void Main(string[] args)
{
// Path to the TGZ file
string tgzFilePath = "output.tgz";
// Directory where the contents will be extracted
string extractionPath = "extracted_content";
// Create an instance of IronGZipArchive
IronGZipArchive archive = new IronGZipArchive();
// Extract the tgz archive to the specified directory
archive.ExtractArchiveToDirectory(tgzFilePath, extractionPath);
// Inform the user that extraction is complete
Console.WriteLine("Extraction complete. Files are located at: " + extractionPath);
}
}
using IronGZip;
// Make sure to reference the IronGZip library in your project
class Program
{
static void Main(string[] args)
{
// Path to the TGZ file
string tgzFilePath = "output.tgz";
// Directory where the contents will be extracted
string extractionPath = "extracted_content";
// Create an instance of IronGZipArchive
IronGZipArchive archive = new IronGZipArchive();
// Extract the tgz archive to the specified directory
archive.ExtractArchiveToDirectory(tgzFilePath, extractionPath);
// Inform the user that extraction is complete
Console.WriteLine("Extraction complete. Files are located at: " + extractionPath);
}
}
Imports IronGZip
' Make sure to reference the IronGZip library in your project
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Path to the TGZ file
Dim tgzFilePath As String = "output.tgz"
' Directory where the contents will be extracted
Dim extractionPath As String = "extracted_content"
' Create an instance of IronGZipArchive
Dim archive As New IronGZipArchive()
' Extract the tgz archive to the specified directory
archive.ExtractArchiveToDirectory(tgzFilePath, extractionPath)
' Inform the user that extraction is complete
Console.WriteLine("Extraction complete. Files are located at: " & extractionPath)
End Sub
End Class
Explanation:
Namespace Usage: The
using IronGZip;
directive includes the IronGZip library, ensuring you can utilize its classes and methods.Variable Declarations:
tgzFilePath
holds the path to the TGZ file you intend to extract.extractionPath
is the directory where the extracted files will be stored.
Archive Extraction:
- An instance of
IronGZipArchive
calledarchive
is created, which contains the methodExtractArchiveToDirectory
. - The
ExtractArchiveToDirectory
method takes two arguments: the path to the TGZ file and the directory path for extraction.
- An instance of
- Completion Message:
- Once the extraction is finished, a message is printed to the console, notifying the user of the extraction completion and the location of the extracted content.
- Once the extraction is finished, a message is printed to the console, notifying the user of the extraction completion and the location of the extracted content.