PHPackages                             lopo/olef - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. lopo/olef

ActiveLibrary[File &amp; Storage](/categories/file-storage)

lopo/olef
=========

PHP library for reading and writing Microsoft OLE Compound Documents (Structured Storage / CFB format)

v0.9.0(10mo ago)12MPL-2.0PHPPHP &gt;=8.4

Since Jul 6Pushed 10mo agoCompare

[ Source](https://github.com/Lopo/OleF)[ Packagist](https://packagist.org/packages/lopo/olef)[ RSS](/packages/lopo-olef/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (10)Versions (2)Used By (0)

OleF
====

[](#olef)

**OleF** is a PHP port of the [OpenMCDF](https://github.com/ironfede/openmcdf) library (version 2.4), originally written in C# for the .NET platform. It allows developers to manipulate [Microsoft Compound Document Files](https://msdn.microsoft.com/en-us/library/dd942138.aspx) (also known as OLE structured storage).

In addition to porting the OpenMCDF logic, several .NET framework classes and functionalities were reimplemented to provide equivalent behavior in PHP, as these are not natively available in the language.

This port is inspired by and partially based on code and ideas from:

- [OpenMCDF](https://github.com/ironfede/openmcdf) (C#/.NET, MPL-2.0)
- [olefile](https://github.com/decalage2/olefile) (Python, BSD)
- [Microsoft .NET Framework](https://github.com/dotnet/runtime) (C#, MIT)

---

Features
--------

[](#features)

- Read/write operations on streams and storages
- Traversal of the structure tree
- Support for version 3 and 4 of the OLE specification
- Lazy loading to minimize memory usage
- Intuitive API for working with structured files
- OLE Properties extension for DocumentSummaryInfo and SummaryInfo streams

---

Performance
-----------

[](#performance)

OleF requires the `ds` PHP extension or `php-ds/php-ds` polyfill. While both provide the same functionality, there's a significant performance difference:

- **ext-ds (native C extension)**: Recommended for production use
- **php-ds/php-ds (PHP polyfill)**: 51x slower on average, up to 7,067x slower for large operations

**Example performance differences**:

- Creating 256 streams: ext-ds ~6.9s, php-ds ~5m 52s (51x slower)
- 800MB file operations: ext-ds ~22m, php-ds ~1d 19h (would exhaust 8GB memory)
- Large file append (2.1GB): ext-ds ~20s, php-ds ~39.5h (7,067x slower)

### Performance Measurements

[](#performance-measurements)

Tests were performed on:

- **Hardware**: AMD Ryzen 9 9950X, 192GB RAM, Samsung SSD 990 PRO
- **OS**: Arch Linux 6.15.4
- **PHP**: 8.4.7 (AUR optimized build)
- **ext-ds**: git version (php84-ds-git r1.3d2762f-1)
- **php-ds/php-ds**: v1.7.0

For best performance, install the native extension:

```
# Debian/Ubuntu
sudo apt-get install php-ds

# macOS with Homebrew
pecl install ds

# Or compile from source
git clone https://github.com/php-ds/ext-ds
cd ext-ds
phpize
./configure
make
sudo make install
```

---

Usage Examples
--------------

[](#usage-examples)

### Create a new compound file

[](#create-a-new-compound-file)

```
$b = str_repeat("\x00", 10000);

$of = new \OleF\OleFile;
$myStream = $of->RootStorage->addStream('MyStream');

$myStream->setData($b);
$of->saveAs('MyCompoundFile.cfs');
$of->close();
```

### Open an existing file (e.g., Excel workbook) and read a stream

[](#open-an-existing-file-eg-excel-workbook-and-read-a-stream)

```
//A xls file should have a Workbook stream
$of = \OleF\OleFile::open('report.xls');
$foundStream = $of->RootStorage->getStream('Workbook');
$temp = $foundStream->getData();
// do something with $temp
$of->close();
```

### Add storage and stream items

[](#add-storage-and-stream-items)

```
// Open existing file in update mode (or create new one first)
$of = \OleF\OleFile::open('existing.cfs', true);
$st = $of->RootStorage->addStorage('MyStorage');
$sm = $st->addStream('MyStream');
```

### Remove items

[](#remove-items)

```
$of->RootStorage->delete('AStream'); // 'AStream' item is assumed to exist
```

### Commit changes

[](#commit-changes)

```
$of->RootStorage->addStream('MyStream')->setData($buffer);
$of->commit();
```

### Purge unused space (shrink file)

[](#purge-unused-space-shrink-file)

```
\OleF\OleFile::shrinkOleFile('MultipleStorage_Deleted_Compress.cfs');
```

### Handle OLE Properties

[](#handle-ole-properties)

```
$of = \OleF\OleFile::open('report.xls');
$pc = new \OleF\Extensions\OLEProperties\OLEPropertiesContainer($of->RootStorage->getStream("\x05SummaryInformation"));
foreach ($pc->Properties as $p) {
    // ...
}
```

---

More about OLE Compound Files
-----------------------------

[](#more-about-ole-compound-files)

Compound files store multiple streams of information (such as document summary and user data) in a single container. This file format is used by many applications, including all Microsoft Office documents up to the 2007 release, Windows thumbnail cache files (thumbs.db), Outlook .msg files, Visual Studio .suo files, and some audio/video editing project files.

---

License
-------

[](#license)

This project is licensed under the [Mozilla Public License 2.0 (MPL-2.0)](https://www.mozilla.org/MPL/2.0/).

- All files derived from or inspired by the above projects are subject to the terms of their respective licenses (primarily MPL-2.0).
- Contributions to this project must be compatible with MPL-2.0.
- For details, see the [`LICENSE`](./LICENSE) file.

---

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

[](#contributing)

Please respect the MPL-2.0 license and credit original authors when contributing.

---

**Author:** [Lopo](https://github.com/Lopo)
**Project URL:**

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance54

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

317d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d3b4c53171d8cdad8ad9d5847e23fb65c22a1537fccd116a7021b87392ecaf2?d=identicon)[Lopo](/maintainers/Lopo)

---

Top Contributors

[![Lopo](https://avatars.githubusercontent.com/u/279973?v=4)](https://github.com/Lopo "Lopo (1 commits)")

---

Tags

compoundoleCFBstructured-storagecompound-fileole2

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lopo-olef/health.svg)

```
[![Health](https://phpackages.com/badges/lopo-olef/health.svg)](https://phpackages.com/packages/lopo-olef)
```

###  Alternatives

[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[fof/upload

The file upload extension for the Flarum forum with insane intelligence.

188171.7k15](/packages/fof-upload)[nette/assets

🎨 Nette Assets: elegant asset management for PHP with versioning, caching and mappers for various storage backends.

41346.6k7](/packages/nette-assets)

PHPackages © 2026

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