Skip to content

Commit 77cf9bb

Browse files
author
Robert D. Vincent
committed
Address more comments.
1 parent 6cfad47 commit 77cf9bb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

nibabel/externals/netcdf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ def __init__(self, filename, mode='r', mmap=None, version=1):
212212
mmap = True
213213
try:
214214
self.fp.seek(0, 2)
215-
self.file_bytes = self.fp.tell()
216-
self.fp.seek(0)
217215
except ValueError:
218216
self.file_bytes = -1 # Unknown file length (gzip).
217+
else:
218+
self.file_bytes = self.fp.tell()
219+
self.fp.seek(0)
219220

220221
self.use_mmap = mmap
221222
self.version_byte = version
@@ -606,7 +607,7 @@ def _read_var_array(self):
606607
else: # not a record variable
607608
# Calculate size to avoid problems with vsize (above)
608609
a_size = reduce(mul, shape, 1) * size
609-
if self.file_bytes >= 0 and begin_+a_size > self.file_bytes:
610+
if self.file_bytes >= 0 and begin_ + a_size > self.file_bytes:
610611
data = fromstring(b'\x00'*a_size, dtype=dtype_)
611612
elif self.use_mmap:
612613
mm = mmap(self.fp.fileno(), begin_+a_size, access=ACCESS_READ)
@@ -615,6 +616,9 @@ def _read_var_array(self):
615616
else:
616617
pos = self.fp.tell()
617618
self.fp.seek(begin_)
619+
# Try to read file, which may fail because the data is
620+
# at or past the end of file. In that case, we treat
621+
# this data as zeros.
618622
buf = self.fp.read(a_size)
619623
if len(buf) < a_size:
620624
buf = b'\x00'*a_size

0 commit comments

Comments
 (0)