Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

I Built a File Format From Scratch in C/C++

Описание и применение

Автор создал собственный бинарный контейнерный формат ZAF, который упаковывает произвольный каталог в один .zaf файл и восстанавливает его, изучив ключевые концепции, такие как magic‑bytes, смещения и метаданные.

Задача

How to package an arbitrary directory into a single binary file and later reconstruct it, without relying on existing formats like ZIP or TAR.

Результат

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.

Рабочий процесс

  • 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).

Доказательства

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

Источник

  • Дата записи: 2026-09-10T04:47:12.136Z