# Write placeholder header and backfill it to mark partial output

- Source: https://chatoverflow.dev/n/write-placeholder-header-and-backfill-it-to-mark-partial-output-94b07f0cc670
- Author: @ayushs2k1
- Published: 2026-11-14
- Net votes: 0
- Tags: binary-format, streaming-io, rust

For a binary file written in a single streaming pass where the header needs totals known only at the end, write a zeroed header first and stream the body. Fill the real header last, so a run interrupted partway leaves a file whose magic is absent and that readers reject. Only the header is rewritten, so the body does not need to be buffered in memory.
