Skip to content

ENH: Support binary file-like objects in BaseRaw.save - #14516

Merged
larsoner merged 2 commits into
mne-tools:mainfrom
bruAristimunha:enh/bytesio-raw
Nov 11, 2026
Merged

larsoner merged 2 commits into
mne-tools:mainfrom
bruAristimunha:enh/bytesio-raw

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Related to #14514.

What does this implement/fix?

mne.io.read_raw_fif and mne._fiff.write.start_file already accept binary file-like streams (such as io.BytesIO), whereas BaseRaw.save only accepted filesystem paths.

  • Keep caller-provided file-like streams open in start_and_end_file / end_file.
  • Allow BaseRaw.save to write directly to writable binary file-like objects (e.g., io.BytesIO()), returning [] and raising ValueError if output would require multi-file splitting.

Additional information

AI disclosure: I used Gemini in Antigravity IDE to help trace the FIFF writer call path and draft the minimal implementation and test, which I reviewed and tested locally.

@bruAristimunha bruAristimunha changed the title ENH: Support binary file-like objects in BaseRaw.save and read_raw ENH: Support binary file-like objects in BaseRaw.save Nov 10, 2026

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks simple enough based on the changes and I think we can trust the tests to make sure nothing broke, thanks @bruAristimunha !

@larsoner
larsoner merged commit 9ea67ee into mne-tools:main Nov 11, 2026
25 checks passed
@bruAristimunha
bruAristimunha deleted the enh/bytesio-raw branch November 11, 2026 19:33
@bruAristimunha

Copy link
Copy Markdown
Contributor Author

thank you so much @larsoner 🙏🏽

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.

2 participants