PHPackages                             danrossiter/binary-compound-file - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. danrossiter/binary-compound-file

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

danrossiter/binary-compound-file
================================

Pure PHP library for reading Microsoft Compound Binary File Format (CFBF/OLE) documents. Supports both little-endian and big-endian files with stream wrapper interface.

v1.0.0(5mo ago)542[2 issues](https://github.com/thenadz/binary-compound-file-reader/issues)GPL-3.0-or-laterPHPPHP ^7.4 || ^8.0CI passing

Since Dec 15Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/thenadz/binary-compound-file-reader)[ Packagist](https://packagist.org/packages/danrossiter/binary-compound-file)[ RSS](/packages/danrossiter-binary-compound-file/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Binary Compound File Reader
===========================

[](#binary-compound-file-reader)

[![PHP Version](https://camo.githubusercontent.com/d13dfb44e651198d8c00c74fa3d2b3530afedd52f1377165a0e937476f1b32d5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64616e726f7373697465722f62696e6172792d636f6d706f756e642d66696c65)](https://packagist.org/packages/danrossiter/binary-compound-file)[![License](https://camo.githubusercontent.com/c9b5bdabd511da17f3b37f139447765c3aa91c4fbcd249321b092d9fc6c518c5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7468656e61647a2f62696e6172792d636f6d706f756e642d66696c652d726561646572)](https://github.com/thenadz/binary-compound-file-reader/blob/master/LICENSE.txt)[![Tests](https://camo.githubusercontent.com/d3b7361f731fd9c5bc763b91711de5c41f26b4cbae071ebfb587cf2042107253/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7468656e61647a2f62696e6172792d636f6d706f756e642d66696c652d7265616465722f63692e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473)](https://github.com/thenadz/binary-compound-file-reader/actions)

A modern, high-performance PHP library for reading Microsoft Compound Binary File Format (CFBF/OLE) documents.

The compound file format goes by several names: "Object Linking and Embedding (OLE) Compound File (CF)", "Compound Binary File", "Compound Document File", and "OLE2." This format creates a filesystem within a file and is used by `.doc`, `.xls`, `.ppt`, and other Microsoft Office files.

This library was designed to address the lack of quality options for parsing [compound file binary format](https://en.wikipedia.org/wiki/Compound_File_Binary_Format) natively in PHP. Existing implementations were either slow or made assumptions that didn't conform to the specification. This library prioritizes **speed** and **standards compliance**, ensuring broad compatibility and excellent performance at scale.

Features
--------

[](#features)

- **Full CFBF Spec Compliance**: Properly handles FAT, DIFAT, and mini-FAT chain structures
- **Stream Wrapper**: PHP stream wrapper for seamless resource-based access
- **Big-Endian Support**: Correctly parses both little-endian (standard) and big-endian compound files
- **64-bit File Support**: Handles large files with 64-bit ulSize fields in version 4+ files
- **UTF-16 Encoding**: Properly converts UTF-16LE/BE stream names to UTF-8
- **PHP 7.4+ Compatible**: Works with PHP 7.4, 8.0, 8.1, 8.2, and 8.3+
- **PSR-4 Autoloading**: Composer-based installation and autoloading
- **Fully Tested**: Comprehensive PHPUnit test suite with unit and integration tests

Installation
------------

[](#installation)

Install via Composer:

```
composer require danrossiter/binary-compound-file
```

Usage
-----

[](#usage)

To use the library, there are two options depending on your specific needs: a [stream wrapper](http://php.net/manual/en/class.streamwrapper.php) or raw access to the parsed file fields. Below, both of these approaches are demonstrated. The stream option provides a nice abstraction if you have functions that accept a PHP resource that you want to pass in a single stream from a compound file.

### Basic Usage

[](#basic-usage)

```
use DanRossiter\BinaryCompoundFile\CompoundFile;
use DanRossiter\BinaryCompoundFile\StorageType;

// Open the compound file
$handle = fopen('document.doc', 'rb');
$cfb = new CompoundFile($handle);

// Extract a specific stream
$wordDocStream = $cfb->getDirectory('WordDocument');
$content = $cfb->getStream($wordDocStream);

// Iterate through all streams
$directories = $cfb->getDirectories();
foreach ($directories as $name => $dir) {
    if ($dir->getMse() === StorageType::STREAM) {
        $streamContent = $cfb->getStream($dir);
        echo "Stream: $name, Size: " . strlen($streamContent) . " bytes\n";
    }
}

fclose($handle);
```

### Stream Wrapper

[](#stream-wrapper)

For seamless integration with PHP's stream functions:

```
use DanRossiter\BinaryCompoundFile\CompoundFileStream;

// Register the stream wrapper
stream_wrapper_register('cfbf', CompoundFileStream::class);

// Access streams using the cfbf:// protocol
$handle = fopen('cfbf://document.doc#WordDocument', 'rb');
$content = stream_get_contents($handle);
fclose($handle);
```

### Examples

[](#examples)

See the [`examples/`](examples/) directory for complete working examples:

- [`extract-all-streams.php`](examples/extract-all-streams.php) - Extract all streams to individual files
- [`stream-wrapper.php`](examples/stream-wrapper.php) - Using the cfbf:// stream wrapper
- [`inspect-structure.php`](examples/inspect-structure.php) - Analyze file structure and directory tree
- [`create-bigendian-test.php`](examples/create-bigendian-test.php) - Generate big-endian test files

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- No external dependencies (pure PHP implementation)

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
composer test
```

### Code Quality

[](#code-quality)

```
# Static analysis
composer phpstan

# Code style checking
composer cs-check

# Code style fixing
composer cs-fix
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover a security vulnerability, please see [SECURITY.md](SECURITY.md) for reporting procedures.

Roadmap
-------

[](#roadmap)

- Write support (currently read-only)
- Additional format validation and corruption detection
- Convenience classes: `WordFile`, `ExcelFile`, `PowerPointFile` with format-specific methods

License
-------

[](#license)

GPL-3.0-or-later. See [LICENSE.txt](LICENSE.txt) for details.

Credits
-------

[](#credits)

Created by [Dan Rossiter](https://github.com/thenadz)

Acknowledgments
---------------

[](#acknowledgments)

- [Microsoft's Compound File Binary Format Specification](https://github.com/microsoft/compoundfilereader)
- [OpenOffice Compound Document Format Documentation](http://www.openoffice.org/sc/compdocfileformat.pdf)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance65

Regular maintenance activity

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 87% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

154d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17fb5298e476c66852a973db46189f2508dde2f4c90689461f7dd2db03b4a046?d=identicon)[thenadz](/maintainers/thenadz)

---

Top Contributors

[![thenadz](https://avatars.githubusercontent.com/u/1374212?v=4)](https://github.com/thenadz "thenadz (20 commits)")[![viveksundersecondary](https://avatars.githubusercontent.com/u/185572085?v=4)](https://github.com/viveksundersecondary "viveksundersecondary (3 commits)")

---

Tags

docxlsbinarypptolestructured-storagecompound-filecfbf

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/danrossiter-binary-compound-file/health.svg)

```
[![Health](https://phpackages.com/badges/danrossiter-binary-compound-file/health.svg)](https://phpackages.com/packages/danrossiter-binary-compound-file)
```

###  Alternatives

[alchemy/binary-driver

A set of tools to build binary drivers

19110.9M39](/packages/alchemy-binary-driver)[comcast/php-legal-licenses

A utility to generate a Licenses file containing the full license text for every dependency in your project for legal purposes.

821.1M9](/packages/comcast-php-legal-licenses)[wapmorgan/binary-stream

A handy tool for working with binary data

52263.1k6](/packages/wapmorgan-binary-stream)[ademarre/binary-to-text-php

Collection of binary-to-text encoding utilities for PHP. Includes Base32 support and much more.

40165.8k](/packages/ademarre-binary-to-text-php)[phar-io/composer-distributor

Base Code for a composer plugin that installs PHAR-files

13581.1k6](/packages/phar-io-composer-distributor)[yaroslavche/bitmask

BitMask, EnumBitMask

3453.7k1](/packages/yaroslavche-bitmask)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
