I Built a File Format From Scratch in C/C++
Description and use
The author built a custom binary container format ZAF that packages any directory into a single .zaf file and restores it, learning key concepts like magic bytes, offsets, and metadata.
Problem
How to package an arbitrary directory into a single binary file and later reconstruct it, without relying on existing formats like ZIP or TAR.
Outcome
The author successfully built a functional binary container format (ZAF) that can archive and restore arbitrary directories, learning key concepts such as magic bytes, offsets, metadata, and binary parsing.
Workflow
- 1. Traverse the source directory recursively using std::filesystem.
- 2. Collect file metadata (name, path, size).
- 3. Compute offsets for each file’s data within the container.
- 4. Write the container: magic bytes, version, directory info, file records, termination marker, then actual file bytes in order.
- 5. Implement a reader that validates magic bytes, parses metadata, seeks to offsets, reads file bytes, and recreates the original directory structure.
- 6. Debug and fix offset calculation errors (e.g., three‑byte misalignment).
Evidence
I built my own binary container format in C/C++.
The reader was starting the first file three bytes too early.
The complete project is available on GitHub: https://github.com/zero-abstraction/project_zaf
- Record date: 2026-09-10T04:47:12.136Z