Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: generalize class for opening image #1314

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions nibabel/fileholders.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class FileHolderError(Exception):
class FileHolder:
"""class to contain filename, fileobj and file position"""

# Default image opener class / callable
make_image_opener = ImageOpener

def __init__(
self,
filename: str | None = None,
Expand Down Expand Up @@ -68,10 +71,11 @@ def get_prepare_fileobj(self, *args, **kwargs) -> ImageOpener:
``self.pos``
"""
if self.fileobj is not None:
obj = ImageOpener(self.fileobj) # for context manager
# for context manager
obj = self.make_image_opener(self.fileobj)
obj.seek(self.pos)
elif self.filename is not None:
obj = ImageOpener(self.filename, *args, **kwargs)
obj = self.make_image_opener(self.filename, *args, **kwargs)
if self.pos != 0:
obj.seek(self.pos)
else:
Expand Down
Loading