Add OLEWrite, the counterpart of OLERead - #65
Merged
Progi1984 merged 1 commit intoSep 5, 2026
Conversation
Co-Authored-By: business.arshgoyal@gmail.com <business.arshgoyal@gmail.com>
4 tasks
Progi1984
approved these changes
Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Microsoft\OLEReadcan read an OLE compound document, but nothing here can write one, so every PHPOffice project that emits a binary Microsoft format has to carry its own compound-file writer. This addsMicrosoft\OLEWrite, a minimal version 3 (512 byte sectors) compound file writer that is the direct counterpart ofOLERead:It handles what a real compound file needs and nothing more: streams under 4096 bytes go into the mini stream (with its own mini FAT), larger ones get whole sectors, names are sorted with the compound-file ordering (length first, then case-insensitive), and the directory entries are emitted as a balanced tree so readers that walk the tree — including
OLERead— find every stream. It throws when a name is empty or longer than 31 characters, and when the document would need more than the 109 FAT sector numbers the header can reference (no DIFAT sectors are written).Tests round-trip documents through
OLERead(small, large and empty streams) and cover the rejected cases.phpunit,phpstan(level 7) andphpmdpass locally.Context: PHPOffice/PHPWord#2929 adds a
.docwriter and currently carries this class asPhpWord\Shared\OLEWrite; per the maintainer's request there it belongs in Common first, after which PHPWord will depend on it instead of shipping its own copy.Written by Devin