How yanikusgg/huffman-archiver works
Project type and purpose
• This is a command-line file archiver written in C++ that implements Huffman coding for lossless compression and decompression.
• It’s composed of a small core library (Huffman tree construction, bit‐level I/O, encoding/decoding) plus a CLI front end.
File structure
• CMakeLists.txt → build configuration (CMake).
• main.cpp → parses command-line arguments, drives compress/decompress logic.
• bitstream.cpp/.h → low-level bit reader/writer for packed output.
• coder.cpp/.h → high-level encode() and decode() interfaces.
• huffmantree.cpp/.h → frequency analysis and Huffman tree construction.
• huffman_constants.h → constants (e.g., special markers).
Extract insights from README
• CLI interface:
• archiver -c archive_name file1 [file2 …] → compress → write one archive file.
• archiver -d archive_name → decompress.
• archiver -h → help.
• All filenames and directory context preserved.
a. Main components:
• CLI Parser (main.cpp)
• Compression Engine (coder)
• Huffman Tree Builder (huffmantree)
• Bitstream I/O (bitstream)
• File I/O layer (filesystem reads/writes)
b. Relationships & data flow:
1. User enters CLI command → CLI Parser
2. Parser dispatches to Compression or Decompression use case in Coder
3a. Compress path:
• File I/O reads raw bytes → Huffman Tree Builder computes frequencies → builds tree → derives codebook
• Bitstream I/O writes header (tree structure + constants) → encodes file bytes via codebook → writes bitstream → closes archive
3b. Decompress path:
• Bitstream I/O reads archive header → reconstructs Huffman tree → reads bitstream → decodes bits → File I/O writes original files
c. Architectural patterns & design principles:
• Modular separation: CLI layer, core algorithm modules, I/O layer
• Pipeline pattern: sequential processing stages for compress/decompress
• Single Responsibility Principle: each module has one well-defined role
d. Key technologies & frameworks:
• C++17 (or later)
• CMake for build orchestration
• Standard filesystem library for file operations