Skip to content

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

Open
francisdb wants to merge 1 commit into
mdsteele:masterfrom
francisdb:feat/copy-to
Open

feat: add CompoundFile::copy_to for writing a compacted copy#92
francisdb wants to merge 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.
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.

1 participant