How 7-Zip Handles GZ, BZ2, and XZ Archives
This article explains how the 7-Zip utility processes GZ, BZ2, and XZ single-file compressed formats during extraction and creation. Unlike multi-file container formats like ZIP or 7z, GZ, BZ2, and XZ are Unix-derived stream compression formats designed to compress only one file at a time. Understanding how 7-Zip navigates single-file limitations, handles compound tarballs, and applies distinct compression algorithms will help you manage these archives efficiently.
Single-File Compression Architecture
Formats like GZIP (.gz), BZIP2 (.bz2), and XZ (.xz) do not possess native archiving capabilities. They do not store directory structures, file metadata collections, or multiple files independently. Instead, they apply a compression algorithm directly to a single byte stream.
7-Zip recognizes this distinction natively. When opening or creating these formats, 7-Zip restricts operations to a single data payload rather than treating the file as a standard directory-like container.
Decompressing GZ, BZ2, and XZ Files
When you open a standalone .gz, .bz2, or
.xz file in 7-Zip, the software extracts the single
enclosed payload directly:
- Direct Extraction: 7-Zip reads the compressed
stream and extracts the original file to your target directory,
stripping the outer extension (for example, turning
document.txt.gzintodocument.txt). - Handling Tarballs (.tar.gz, .tar.bz2, .tar.xz):
Because single-file compressors cannot package folders, Unix systems
bundle files into a
.tararchive before compressing it. 7-Zip handles this through nested navigation. When you open a.tar.gzfile in the 7-Zip GUI, double-clicking the file first decompresses the GZ layer in memory, presenting the inner.tarcontainer. Double-clicking the.tarcontainer then reveals the actual files and folders. Using the right-click context menu "Extract Here" or "Extract to [Folder]" on a compound archive in Windows will often require extracting twice, unless using automated extraction scripts.
Creating GZ, BZ2, and XZ Archives
When using 7-Zip to create an archive:
- Single-Item Selection: If you select a single file in Windows Explorer or 7-Zip File Manager and open the "Add to Archive" dialog, GZip, BZip2, and XZ will appear as valid options in the "Archive format" dropdown.
- Multiple-Item Restriction: If you select multiple
files or a folder, 7-Zip automatically removes GZip, BZip2, and XZ from
the format options. To compress multiple files into these formats using
7-Zip, you must first create a
.tararchive containing your data, and then compress that resultant.tarfile into.gz,.bz2, or.xz.
Compression Algorithms Used by 7-Zip
7-Zip employs different underlying engines for each format:
- GZ (Deflate): Uses an optimized Deflate engine. 7-Zip's implementation of Deflate often achieves slightly higher compression ratios than standard GNU gzip implementations at equivalent speed settings.
- BZ2 (Bzip2): Uses the Burrows-Wheeler transform algorithm. It achieves better compression ratios than GZ on text-heavy files, though compression and extraction speeds are significantly slower.
- XZ (LZMA2): Uses the LZMA2 compression algorithm,
which is the same core engine used in native
.7zarchives. It delivers exceptionally high compression ratios and fast decompression, making it the most space-efficient format of the three within 7-Zip.