Skip to content

MAIN: Flush writer(s) after writing file meta and dataset#690

Merged
Enet4 merged 3 commits intoEnet4:masterfrom
naterichman:flush-writer
Oct 1, 2025
Merged

MAIN: Flush writer(s) after writing file meta and dataset#690
Enet4 merged 3 commits intoEnet4:masterfrom
naterichman:flush-writer

Conversation

@naterichman
Copy link
Copy Markdown
Contributor

While noodling around on #649 I came across this line of docs on std::io::BufWriter

It is critical to call flush before BufWriter is dropped. Though dropping will attempt to flush the contents of the buffer, any errors that happen in the process of dropping will be ignored. Calling flush ensures that the buffer is empty and thus dropping will not even attempt file operations.

This PR adds a flush method to each of the dataset writing "stack" (StatefulEncoder and DataSetWriter), which is then called in the FileDicomObject::write_dataset_impl to ensure the writer (specifically the BufWriter used in both write_all, write_to_file, and write_dataset) are flushed before being dropped.

* In dataset serialization, add a final `flush` call to underlying
  writer, since `BufWriter` is the primary writer used, and the docs
  specify that `flush` should be called before `drop`
@Enet4 Enet4 added A-lib Area: library C-object Crate: dicom-object C-parser Crate: dicom-parser labels Oct 1, 2025
Copy link
Copy Markdown
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK. It's better to check that the last bytes were written than to encounter weird edge cases one day and spend hours debugging it. Thanks!

@Enet4 Enet4 merged commit 8d82ab8 into Enet4:master Oct 1, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lib Area: library C-object Crate: dicom-object C-parser Crate: dicom-parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants