Skip to content

Commit b4b2c23

Browse files
committed
FIX: Do not re-create fileobj when passed to DGF
1 parent 2fb5bf3 commit b4b2c23

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

nibabel/openers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ class DeterministicGzipFile(gzip.GzipFile):
4747
to a modification time (``mtime``) of 0 seconds.
4848
"""
4949
def __init__(self, filename=None, mode=None, compresslevel=9, fileobj=None, mtime=0):
50+
# These two guards are copied from
51+
# https://github.com/python/cpython/blob/6ab65c6/Lib/gzip.py#L171-L174
5052
if mode and 'b' not in mode:
5153
mode += 'b'
52-
if filename:
54+
if fileobj is None:
5355
fileobj = self.myfileobj = open(filename, mode or 'rb')
5456
return super().__init__(filename="", mode=mode, compresslevel=compresslevel,
5557
fileobj=fileobj, mtime=mtime)

0 commit comments

Comments
 (0)