Skip to content

feat: add CompoundFile::copy_to for writing a compacted copy - #92

Merged
mdsteele merged 1 commit into
mdsteele:masterfrom
francisdb:feat/copy-to
Sep 14, 2026
Merged

mdsteele merged 1 commit into
mdsteele:masterfrom
francisdb:feat/copy-to

Conversation

@francisdb

Copy link
Copy Markdown
Contributor

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_to writes 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.

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.
@mdsteele
mdsteele merged commit 723f08b into mdsteele:master Sep 14, 2026
4 checks passed
@francisdb
francisdb deleted the feat/copy-to branch September 15, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction after writing shorter streams.

2 participants