How 7-Zip Handles Zero-Byte Files in Archives
When archiving data, encountering zero-byte or empty files is common, particularly in software development projects and system backups. This article explains how 7-Zip processes, stores, and extracts zero-byte files across different archive formats, detailing how it preserves file metadata without allocating payload storage, how it flags empty files internally, and how it restores them reliably upon extraction.
Metadata Preservation Without Payload Data
A zero-byte file contains no data payload, meaning there is nothing for compression algorithms like LZMA, LZMA2, or Deflate to compress. Instead of running a compression algorithm on non-existent data, 7-Zip bypasses the data compression stage entirely.
However, 7-Zip does not discard the file. It retains all associated filesystem metadata, which typically includes:
- The full file name and relative directory path
- File timestamps (Creation, Last Modified, and Last Accessed dates)
- File attributes (such as Read-Only, Hidden, or System flags in Windows; POSIX permissions in Linux)
Format-Specific Handling
How 7-Zip structures a zero-byte file internally depends on the container format selected:
1. The Native 7z Format (.7z)
The native .7z container separates file metadata from
file streams into a centralized header.
- Header Flags: 7-Zip marks empty files using an
internal header property called
IsEmptyStream(orIsEmptyFile). This boolean flag informs the decompressor that the file exists within the directory hierarchy but requires zero bytes from the compressed data stream. - Storage Footprint: The zero-byte file takes up no space in the packed data stream. The only overhead it introduces is a few bytes in the central header to encode the name, timestamps, and attributes.
- Solid Archiving: In solid 7z archives, where multiple files are grouped into a continuous stream to improve compression ratios, empty files do not interrupt or affect the solid stream because they contribute zero bytes to the data pipeline.
2. The ZIP Format (.zip)
When creating standard ZIP archives, 7-Zip complies with the official PKWARE ZIP specification:
- Headers: 7-Zip writes a Local File Header before the entry and a Central Directory record at the end of the archive.
- Size Fields: Both the "Compressed Size" and
"Uncompressed Size" fields are explicitly set to
0. - CRC-32 Checksum: The CRC-32 checksum for a
zero-byte file is set to
0x00000000. - Data Block: No compressed data block is written between the local header and the next entry.
3. TAR and Other Formats (.tar, .wim)
- In POSIX TAR archives, 7-Zip writes a standard 512-byte header block
defining the file metadata with a size field of
0, followed by zero data blocks. - In WIM archives, the empty file is stored as an entry pointing to a null resource hash without creating a stream entry.
Extraction Behavior
During extraction, 7-Zip parses the archive header, reads the metadata, and detects that the uncompressed size is zero bytes:
- It creates the file at the specified target path using standard
operating system APIs (such as
CreateFileon Windows oropen()withO_CREATon Unix-like systems). - It writes zero bytes of content to disk.
- It applies the archived timestamps, permissions, and attributes to the newly created file.
- It closes the file handle immediately.
Because 7-Zip explicitly accounts for empty data streams in its specifications, zero-byte files do not trigger corruption warnings, CRC errors, or unexpected terminations during creation, testing, or extraction.