This directory contains working examples demonstrating various ways to use the Binary Compound File Reader library.
All examples assume you have installed dependencies:
composer installExtracts all streams from a compound file to individual files.
php examples/extract-all-streams.phpWhat it demonstrates:
- Opening a compound file
- Iterating through directory entries
- Filtering for stream types
- Extracting stream content to files
Shows how to use the cfbf:// stream wrapper for seamless integration with PHP's stream functions.
php examples/stream-wrapper.phpWhat it demonstrates:
- Registering the stream wrapper
- Accessing streams via
cfbf://protocol - Reading stream content
- Unregistering the wrapper
Analyzes and displays the internal structure of a compound file.
php examples/inspect-structure.phpWhat it demonstrates:
- Reading file header information
- Detecting byte order (little-endian vs big-endian)
- Displaying directory tree
- Calculating statistics
The examples use these test files from tests/fixtures/:
Dan Rossiter Resume.doc- Little-endian compound fileDan Rossiter Resume-BE.doc- Big-endian compound file (generated)
Basic structure for using the library:
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use DanRossiter\BinaryCompoundFile\CompoundFile;
use DanRossiter\BinaryCompoundFile\DirectoryEntry;
// Open file
$handle = fopen('yourfile.doc', 'rb');
$cfb = new CompoundFile($handle);
// Access streams
$directories = $cfb->getDirectories();
foreach ($directories as $name => $dir) {
if ($dir->getMse() === DirectoryEntry::STGTY_STREAM) {
$content = $cfb->getStream($dir);
// Process content...
}
}
fclose($handle);- Main README - Full documentation
- API Documentation - Detailed API reference
- Tests - More usage examples in test files