feat: add CompoundFile::copy_to for writing a compacted copy - #92
Open
francisdb wants to merge 1 commit into
Open
feat: add CompoundFile::copy_to for writing a compacted copy#92francisdb wants to merge 1 commit into
francisdb wants to merge 1 commit into
Conversation
francisdb
force-pushed
the
feat/copy-to
branch
from
September 9, 2026 05:56
23df375 to
c7ec821
Compare
A compound file never shrinks in place: sectors freed by removing or shrinking streams stay in the file. copy_to writes the same storages and streams, with their CLSIDs, state bits and timestamps, into a fresh file of the same version, which is how Windows compacts a file as well.
francisdb
force-pushed
the
feat/copy-to
branch
from
September 10, 2026 06:14
c7ec821 to
244cbf0
Compare
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.
Closes #55.
A compound file never shrinks in place: sectors freed by removing or shrinking streams stay in the file. This is also how Windows and Wine behave; Microsoft's guidance for compacting is to copy the root storage into a new file with
IStorage::CopyTo, which is what this adds.copy_towrites the same storages and streams, with their CLSIDs, state bits and timestamps, into a fresh file of the same version and returns it. It is available on any readable source, so a read-only file can be compacted into a new writer, and callers who want in-place semantics can copy to a temporary file and rename it over the original.This sidesteps the truncation problem from the issue thread: no trait for resizing the underlying writer is needed, and space freed in the middle of the file is reclaimed too, which trimming the tail never could.