Finalize the change file by writing the trailer. This computes the final blake3 content hash from all hashed sections written so far, writes the 32-byte trailer, and returns the [`WriteOutcome`] containing the hash and statistics. After calling this, the writer is consumed and no more writes are possible. # Required Sections The following sections must have been written before finalizing: - Fi
(mut self)
| 513 | /// - [`FormatError::UnexpectedSection`] if required sections are missing. |
| 514 | /// - I/O errors from writing the trailer. |
| 515 | pub fn finalize(mut self) -> FormatResult<WriteOutcome> { |
| 516 | self.ensure_metadata_complete()?; |
| 517 | if (self.schema_version == SPAN_FORMAT_VERSION) != self.wrote_span_section { |
| 518 | return Err(FormatError::InvalidHeader { |
| 519 | reason: "schema 3 requires exactly one SPAN section; schema 2 forbids it".into(), |
| 520 | }); |
| 521 | } |
| 522 | |
| 523 | // Compute the final hash |
| 524 | let hash = self.hasher.finalize(); |
| 525 | let content_hash = *hash.as_bytes(); |
| 526 | |
| 527 | // Write the trailer |
| 528 | let trailer = Trailer { content_hash }; |
| 529 | trailer.write_to(self.writer)?; |
| 530 | self.stats.total_bytes_written += Trailer::SIZE as u64; |
| 531 | |
| 532 | self.state = WriterState::Finalized; |
| 533 | |
| 534 | Ok(WriteOutcome { |
| 535 | content_hash, |
| 536 | stats: self.stats, |
| 537 | }) |
| 538 | } |
| 539 | |
| 540 | // ── Low-Level: Pre-Compressed Section ────────────────────────── |
| 541 |