1. Peel
  2. The Pith
  3. Anatomy of an archive
Essay · Engineering

Anatomy of an Archive

A file container is not the same thing as a compression algorithm.

By · · Updated · The Pith, no. 5 · 8 min read

An orange dissected into rind and segments, with anatomical annotations

Double-click a ZIP file and it looks like one object. Open it and suddenly there are dozens of objects: documents, directories, images and perhaps another archive. The interface makes that transition feel almost trivial. The underlying representation is anything but.

Somewhere inside that file are instructions describing what the objects are, where their contents begin, how those contents were encoded and what should happen when we reconstruct them. Some archives make those instructions easy to locate. Others require us to process a substantial amount of information before we can even discover what is inside.

That difference matters if we’re building an archive utility. It determines how quickly we can display a directory, whether we can preview one document without extracting everything else, how much memory we need, and what remains accessible when part of the archive becomes damaged.

Three things we tend to call compression

Consider a directory containing three files. We have at least three distinct problems to solve. We need to represent the directory and its entries, encode their contents economically, and provide enough information to reconstruct the result. These problems are related, but they do not require the same mechanism.

A container establishes the structure of the representation. A compression codec transforms bytes into a reversible encoded stream. An index provides a way to locate portions of the representation. A particular format can combine these responsibilities or leave some of them to another layer.

ZIP is a container capable of storing entries using multiple compression methods, including no compression at all. DEFLATE is a compression method. TAR is primarily an archive container, and gzip wraps a DEFLATE stream in its own framing. A .tar.gz file is therefore a TAR representation passed through gzip, not a different name for ZIP (Figure 1).

Fig. 01

Container, codec, index.

Container: names, metadata, boundariesCodecEncoded contentIndexLocations
Figure 1. Conceptual responsibilities, not a required physical layout. Some formats have no separate index.

Opening a ZIP file from the end

A conventional ZIP file has local file records followed by a central directory and an end-of-central-directory record. The local records contain headers and encoded data. The central directory contains an index of entries, including offsets to their local headers. A reader can usually locate the end record near the end of the file, then use it to locate the central directory.

That is an interesting reversal of the way we ordinarily think about reading files. To understand the contents, we often begin at the end. A reader doesn’t need to decompress every entry to enumerate the archive. It needs to locate and interpret the metadata.

The details matter. ZIP64 extends fields that otherwise have limited capacity. Optional data descriptors can carry sizes and checksums after a payload when the writer didn’t know them in advance. Extra fields, comments, encryption and split archives complicate the simple diagram. A real parser must follow the format specification rather than assume that every record has exactly the same shape (Figure 2).

Fig. 02 / Interactive

Explore a ZIP byte by byte.

Three synthetic text files, written with Python’s zipfile and DEFLATE. Choose a region of the file or a record.

Local headers Payload Central directory End record

Figure 2. The fixture’s actual bytes, not simulated records. Offsets start at zero; end offsets are exclusive.

What lives in a header?

A basic ZIP local header begins with a four-byte signature. Fields describe the version required to extract the entry, flags, compression method, timestamps, CRC-32, compressed and uncompressed sizes, and the lengths of the filename and extra data. The filename and extra data follow the fixed 30-byte portion.

A central directory record repeats much of this information and includes other attributes and an offset to the local record. The fixed portion of a conventional central record is 46 bytes. The ordinary end record has a fixed 22-byte portion. These are not complete record sizes when optional variable-length fields are present.

The repetition is useful. A writer can generate local records as it processes files, then emit an index after it has learned the sizes and locations. A reader can use the index to avoid walking every payload. This is a trade-off: additional bytes buy access to information about the contents.

A signature alone is not sufficient evidence that a record is valid. The same bytes might occur inside a compressed payload. Readers need to validate lengths, offsets, structure and consistency before treating bytes as metadata.

TAR: a different organization

TAR approaches the problem from a different direction. In a conventional TAR representation, each entry has a 512-byte header, followed by its content padded to a 512-byte boundary. Two zero-filled blocks mark the logical end of the archive. Implementations may add further blocking padding. Extended headers can describe names, sizes or attributes beyond the basic format.

This arrangement is well suited to sequential processing. A reader can parse a header, consume or skip the corresponding padded contents, and continue to the next entry. In an uncompressed seekable TAR, skipping content can be inexpensive. But there is generally no built-in central directory comparable to ZIP’s.

Now wrap the TAR in an ordinary gzip stream. The header for the third file is no longer at a directly useful offset in the compressed file. Its location is defined in the decoded TAR representation, and decoding a normal DEFLATE stream requires the earlier decoding state. Specialized indexes or independently decodable frames can change that relationship, but a plain compressed TAR does not automatically provide them (Figure 3).

Fig. 03 / Interactive

How much space does one entry occupy?

512-byte header Content Padding

Figure 3. A basic regular-file TAR record only: no extended headers, end markers or outer compression.

Independent entries and solid compression

Suppose we have a thousand related documents. Compressing each one independently allows us to retrieve a single document without recreating the compression state for every preceding document. But it also means that repeated phrases across document boundaries may not contribute to the compression of the next document.

Solid compression can combine multiple files into a shared compression stream or block. This may improve compression when files share substantial structure. In exchange, retrieving an entry late in a solid block may require decoding earlier data in that block. The amount of work depends on the block organization, indexing and decoder capabilities.

Neither arrangement is inherently better. An archive intended for a single complete extraction has a different access pattern from an archive people browse repeatedly. The question is not just how many bytes we saved. It’s how much work the representation requires for the operations we actually perform (Figure 4).

Fig. 04 / Interactive

Retrieve one file.

Figure 4. An illustrative model: equal-size files, decoded in order from the start of a block, stopping at the end of the requested file. It ignores metadata, caching and codec-specific buffering.

Where the extra bytes go

In our earlier articles, we distinguished payload size from complete representation size. Archives make that distinction especially tangible. The same file can have a small encoded payload and a relatively large container overhead. For thousands of tiny entries, filenames, headers and indexes can become a significant fraction of the archive.

We generated three small text files and packaged them in ZIP and TAR, then compressed the TAR with gzip. The values below are actual sizes from those fixtures. They are not a general comparison of format efficiency: the input is deliberately small and repetitive, and TAR writers can use additional record padding (Figure 5).

Fig. 05 / Measured

Payload is not archive size.

EntryOriginal bytesZIP payload bytesCRC-32
notes.txt108320263f546
readme.txt2123e5844c6d
data.txt12899f2f1749
Figure 5. Generated with Python 3.13.5 and zlib 1.3.1, and reproduced byte for byte with Python 3.13.18 and zlib 1.2.12. ZIP uses DEFLATE level 6; gzip uses Python’s default level 9 with mtime=0. Sizes only, not throughput.

Integrity is not the same as recoverability

ZIP commonly uses CRC-32 to detect accidental changes in reconstructed entry data. A checksum gives us evidence that the output matches an expected value, within the limitations of that checksum. It is not a cryptographic authentication mechanism, and it doesn’t provide the information required to repair arbitrary damage.

Independent entries can provide useful recovery boundaries. A damaged payload may leave other entries accessible if their metadata and decoding context remain intact. Damage to an index can make those entries difficult to locate, even if their contents survive. Some recovery tools attempt to reconstruct an index from local records, but descriptors, encryption and inconsistent metadata can complicate that process.

Solid streams present a different problem. Damage may affect subsequent decoding until a usable restart boundary is reached. Recovery records, when present, add redundancy with different guarantees. We should not confuse the ability to detect an error with the ability to recover from it.

What an archive utility actually has to do

When developing an archive experience, I’d separate opening the container from decoding its contents. Opening establishes a representation of the entries and their relationships. Inspecting reads metadata. Previewing requests the information necessary for a particular entry. Extracting writes reconstructed data to a destination.

Each operation has a different contract. A directory listing should not imply that every payload has been verified. A preview should not imply that the entire archive is healthy. Extracting a file requires validating its destination as well as its contents. Entry names and offsets are untrusted information, not instructions to follow without verification.

These distinctions help explain why a native archive browser like Peel can offer a different experience from a traditional extract-first utility. Where a format permits it, the application can expose the contents before materializing them. Where it doesn’t, the engine needs to manage the decoding work while keeping the interface responsive and making the limitations visible.

For Rind, the architectural implication is that format parsing, codec execution, indexing, integrity checking and destination handling deserve separate responsibilities. They can share a common interface without pretending that every format offers identical capabilities.

Reproduce the fixture

The following script recreates the example ZIP and TAR inputs used in the figures. It also verifies that the ZIP entries and gzip-wrapped TAR reconstruct correctly. No files need to be extracted to disk.

import io, zipfile, tarfile, gzip
          files = {'notes.txt': b'An archive is a container.\n'*4,
                   'readme.txt': b'Hello from The Pith.\n',
                   'data.txt': b'ABCD'*32}
          b = io.BytesIO()
          with zipfile.ZipFile(b, 'w') as z:
              for name, data in files.items():
                  info = zipfile.ZipInfo(name, (2026,1,1,0,0,0))
                  info.compress_type = zipfile.ZIP_DEFLATED
                  z.writestr(info, data, compresslevel=6)
          with zipfile.ZipFile(io.BytesIO(b.getvalue())) as z:
              assert z.testzip() is None
              for name, data in files.items():
                  assert z.read(name) == data
                  print(name, z.getinfo(name).compress_size)
          t = io.BytesIO()
          with tarfile.open(fileobj=t, mode='w', format=tarfile.USTAR_FORMAT) as tar:
              for name, data in files.items():
                  info = tarfile.TarInfo(name)
                  info.size = len(data)
                  tar.addfile(info, io.BytesIO(data))
          g = gzip.compress(t.getvalue(), mtime=0)
          assert gzip.decompress(g) == t.getvalue()
          print(len(b.getvalue()), len(t.getvalue()), len(g))

The fixture was generated and checked while preparing this article. It demonstrates layout and size accounting, not the relative speed or security of competing archive engines.

The archive as an object

We tend to think about compression in terms of how much smaller a file becomes. Once we begin examining archive formats, another question becomes equally interesting: what can we do with the representation after we’ve created it?

A container is a set of decisions about boundaries, relationships and access. A codec is a set of decisions about how to represent information. An index is a set of decisions about which parts of that information should be discoverable without processing the rest.

Those decisions affect the experience of opening a file just as much as they affect the size of the file on disk.

The archive icon hides all of that complexity. Understanding what is beneath it gives us a much better foundation for deciding how archive software ought to behave.

References and further reading

Read next · No. 11 · DesignWhy Are We Still Extracting Archives?Once you know where the index lives and where decoding has to start, extracting everything starts to look optional.
Peel's icon: an orange on a cream tile

Get Peel. Free forever.

No account, no ads, no trial. Everything Peel does today stays free, and it keeps itself up to date.

Download Peel 1.4.0 brew install --cask snackstudio/tap/peel
Requirements
macOS 13 Ventura or later, on Apple silicon or Intel.
Install
Open the installer and follow it. Or open the disk image and drag Peel to Applications, or run brew install --cask snackstudio/tap/peel in Terminal.
Updates
Peel updates itself, and every update is signed. To check now, choose Peel ▸ Check for Updates…
Uninstall
Drag Peel to the Trash, or run brew uninstall --cask peel.
Price
Free. No account, no ads, no trial.
Privacy
Your files never leave your Mac, and the app has no analytics. This site counts visits to learn what helps; the privacy policy says how.