Skip to content

FLAC: Avoid buffering the entire file during tag writes - #695

Merged
Serial-ATA merged 4 commits into
Serial-ATA:mainfrom
sxntaxis:flac-bounded-tag-write
Aug 15, 2026
Merged

Serial-ATA merged 4 commits into
Serial-ATA:mainfrom
sxntaxis:flac-bounded-tag-write

Conversation

@sxntaxis

Copy link
Copy Markdown
Contributor

closes #694

This keeps the existing FLAC parsing and metadata encoding, but replaces the final whole-file buffer/splice with a bounded in-place range replacement.

  • Equal-sized metadata is overwritten in place.
  • When metadata grows, the file is extended and the remaining contents are moved backwards in 64 KiB chunks before writing the replacement.
  • When metadata shrinks, the remaining contents are moved forwards and the file is truncated afterward.

The FLAC resize regression now covers FLAC directly. I also checked the historical #549/#607/#608/#640 failure modes, including no-padding/minimal layouts, last-metadata-block handling, leading ID3 data, and metadata shrink/grow. The large-file reproducer from #694 still passes flac -t with the audio signature preserved while avoiding whole-file memory use.

This does not try to solve #445: existing FLAC padding is still handled the same way, so audio may still need to move when metadata size changes.

AI disclosure: I used AI assistance during investigation, prototyping, test design, and drafting. I reviewed the behavior and failure modes, reproduced the tests and measurements locally, and will participate directly in review.

Comment thread lofty/src/flac/write.rs Resolved
@Serial-ATA Serial-ATA added this to the 0.25.1 milestone Aug 13, 2026
Comment thread lofty/src/flac/write.rs Resolved
Comment thread lofty/src/flac/write.rs Resolved
@Serial-ATA
Serial-ATA force-pushed the flac-bounded-tag-write branch from 57a5224 to 4d0b3fb Compare August 15, 2026 17:47
@Serial-ATA
Serial-ATA merged commit 1fee54e into Serial-ATA:main Aug 15, 2026
5 checks passed
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.

FLAC: Tag writes buffer the entire file in memory

2 participants