Skip to content

Commit a4f8c3c

Browse files
committed
detecting if the input is empty early on! Apparently no one needed it ;)
1 parent af4e046 commit a4f8c3c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

nibabel/loadsave.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .filebasedimages import ImageFileError
1818
from .imageclasses import all_image_classes
1919
from .arrayproxy import is_proxy
20-
from .py3k import FileNotFoundError
20+
from .py3k import FileNotFoundError, FileEmptyError
2121
from .deprecated import deprecate_with_version
2222

2323

@@ -38,6 +38,10 @@ def load(filename, **kwargs):
3838
'''
3939
if not op.exists(filename):
4040
raise FileNotFoundError("No such file: '%s'" % filename)
41+
42+
if op.getsize(filename) <= 0:
43+
raise FileEmptyError("Given file is empty: '%s'" % filename)
44+
4145
sniff = None
4246
for image_klass in all_image_classes:
4347
is_valid, sniff = image_klass.path_maybe_image(filename, sniff)

nibabel/py3k.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class FileNotFoundError(IOError):
6767
pass
6868

6969

70+
class FileEmptyError(IOError):
71+
pass
72+
73+
7074
def getexception():
7175
return sys.exc_info()[1]
7276

0 commit comments

Comments
 (0)