A modern C++ library for parsing IFF (Interchange File Format) and RIFF (Resource Interchange File Format) files.
- Multi-format support: Parse IFF-85, RIFF, RF64, RIFX, and BW64 files
- Common formats: Built-in support for WAV, AVI, AIFF, and more
- Event-driven API: Register handlers for specific chunk types
- Iterator interface: Direct control over chunk traversal
- Large file support: Handle files >4GB with RF64/BW64
- Security focused: Configurable limits for chunk size and nesting depth
- Zero dependencies: Header-only core with no external dependencies
- Modern C++: Written in C++17 with clean, idiomatic code
- Comprehensive testing: Extensive test suite with edge case coverage
#include <iff/parser.hh>
#include <iostream>
#include <fstream>
int main() {
std::ifstream file("audio.wav", std::ios::binary);
iff::for_each_chunk(file, [](auto& chunk) {
std::cout << "Found chunk: " << chunk.header.id
<< " (" << chunk.header.size << " bytes)\n";
});
return 0;
}git clone https://github.com/yourusername/libiff.git
cd libiff
mkdir build && cd build
cmake ..
make
sudo make installAdd to your CMakeLists.txt:
find_package(libiff REQUIRED)
target_link_libraries(your_target PRIVATE iff::iff)Or use FetchContent:
include(FetchContent)
FetchContent_Declare(
libiff
GIT_REPOSITORY https://github.com/yourusername/libiff.git
GIT_TAG main
)
FetchContent_MakeAvailable(libiff)
target_link_libraries(your_target PRIVATE iff::iff)#include <iff/parser.hh>
#include <iff/handler_registry.hh>
iff::handler_registry handlers;
// Handle format chunk
handlers.on_chunk_in_form(
iff::fourcc("WAVE"),
iff::fourcc("fmt "),
[](const iff::chunk_event& event) {
if (event.type == iff::chunk_event_type::begin) {
// Read and process format data
uint16_t format;
event.reader->read(&format, sizeof(format));
std::cout << "Audio format: " << format << "\n";
}
}
);
std::ifstream file("audio.wav", std::ios::binary);
iff::parse(file, handlers);iff::parse_options options;
options.max_chunk_size = 100 * 1024 * 1024; // 100MB limit
options.max_depth = 10; // Max nesting depth
options.strict = false; // Continue on errors
iff::parse(file, handlers, options);See QUICKSTART.md for more examples.
| Format | Description | Status |
|---|---|---|
| IFF-85 | Original EA-85 IFF | ✅ Full support |
| RIFF | Resource Interchange File Format | ✅ Full support |
| RF64 | 64-bit RIFF for large files | ✅ Full support |
| RIFX | Big-endian RIFF | ✅ Full support |
| BW64 | Broadcast Wave 64-bit | ✅ Full support |
- Audio: WAV, AIFF, BW64
- Video: AVI
- Images: WebP (VP8)
- 3D: Maya IFF
- Games: Various game formats using IFF chunks
chunk_iterator: Low-level iteration over chunksparser: High-level parsing with event handlershandler_registry: Event handler managementchunk_reader: Safe chunk data readingparse_options: Security and behavior configuration
// Parse with handlers
iff::handler_registry handlers;
handlers.on_chunk(chunk_id, handler_function);
iff::parse(stream, handlers);
// Simple iteration
iff::for_each_chunk(stream, [](auto& chunk) {
// Process chunk
});
// Direct iterator control
auto it = iff::chunk_iterator::get_iterator(stream);
while (it->has_next()) {
auto& chunk = it->current();
// Process chunk
it->next();
}- C++17 compatible compiler
- CMake 3.10 or higher
- (Optional) Doxygen for documentation
cmake -DLIBIFF_BUILD_TESTS=ON \
-DLIBIFF_BUILD_DOCUMENTATION=ON \
-DCMAKE_BUILD_TYPE=Release \
..make test
# or
ctest --verboseAPI documentation can be built with Doxygen:
cmake -DLIBIFF_BUILD_DOCUMENTATION=ON ..
make docView documentation at build/docs/html/index.html.
libiff/
├── include/iff/ # Public headers
│ ├── parser.hh # High-level parsing API
│ ├── chunk_iterator.hh
│ ├── handler_registry.hh
│ └── ...
├── src/libiff/ # Implementation
├── unittest/ # Test suite
├── examples/ # Example programs
└── docs/ # Documentation
Contributions are welcome! Please feel free to submit pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Use modern C++ features (C++17)
- Follow existing code formatting
- Add tests for new functionality
- Update documentation as needed
- Zero-copy reading: Chunks are read directly from stream
- Lazy evaluation: Data is only read when requested
- Efficient iteration: Minimal overhead for chunk traversal
- Memory safe: No manual memory management required