Create GZIP
GZIP, which stands for 'GNU Zip,' is an essential file compression utility widely used in Unix and Linux systems. It effectively reduces file sizes for optimized storage and faster data transmission by applying the GZIP compression algorithm. Compressed files are marked with a '.gz' extension and can be effortlessly decompressed to restore their original state.
GZIP is the preferred choice for compressing individual files. It is standard practice to create compressed archives by consolidating multiple files into a single TAR archive and then applying GZIP compression. The resulting files will bear the combined extensions, such as .tar.gz or .tgz.
When it comes to compressing large text-based data or streaming data like HTTP, GZIP outperforms the traditional Zip format. IronZip stands out by supporting all compression formats, enabling developers to transition seamlessly between GZIP and Zip as needed.
Creating GZip File with C#
- using IronZip;
- using var archive = new IronGZipArchive();
- archive.Add("output.tar");
- archive.SaveAs("output.tgz");
Creating an Empty gzip Archive
To start, we import the IronZip
namespace, which allows us to utilize the library. We then create a new gzip archive using the IronGZipArchive
constructor inside a using
statement, which helps establish an empty gzip archive.
Adding Files to the Archive
Before we complete the saving process, we can add files to the archive using the Add
method by providing their absolute paths. You can add one or multiple files, including a variety of formats such as images, documents (like DOCX and PDF), audio files (like MP3 and WAV), and even other gzip archives. In this instance, we will demonstrate how to incorporate a TAR archive to illustrate adding multiple files.
For detailed information about the types of files you can include, please check the documentation here.
Saving and Exporting the Archive
Finally, we save and export the archive with the SaveAs
method, naming it output.tgz
. It’s important to note that since we included a TAR archive within the GZIP, the output file extension reflects both formats, resulting in .tgz
.