Skip to content

Commit 947034d

Browse files
committed
Test TransferSyntax, fix zipped reading.
1 parent 9d0cdee commit 947034d

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

nibabel/nifti1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def _check_meta(self):
426426
is_implicit_VR = False
427427
is_little_endian = False
428428
elif transfer_syntax == dicom.UID.DeflatedExplicitVRLittleEndian:
429-
zipped = fileobj.read()
429+
zipped = self._bio.read()
430430
unzipped = zlib.decompress(zipped, -zlib.MAX_WBITS)
431431
self._bio = BytesIO(unzipped) # a file-like object
432432
is_implicit_VR = False
@@ -483,6 +483,7 @@ def _mangle(self, value):
483483
from dicom.filebase import DicomFileLike
484484
from dicom.values import converters as dicom_converters
485485
import dicom.UID
486+
import zlib
486487
from io import BytesIO
487488
except ImportError:
488489
"""Fall back to standard reader if pydicom unavailable."""
Binary file not shown.
362 Bytes
Binary file not shown.
362 Bytes
Binary file not shown.

nibabel/tests/test_nifti1.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,18 @@ def test_nifti_dicom_extension():
11441144

11451145
dcmext.write_to(BytesIO(),False)
11461146

1147+
dicomtestfiles=[
1148+
('data/0_ExplicitVRBigEndian.dcm',dicom.UID.ExplicitVRBigEndian),
1149+
('data/0_ExplicitVRLittleEndian.dcm',dicom.UID.ExplicitVRLittleEndian),
1150+
('data/0_DeflatedExplicitVRLittleEndian.dcm',dicom.UID.DeflatedExplicitVRLittleEndian)]
1151+
for fname,encoding in dicomtestfiles:
1152+
with open(fname,'rb') as dim:
1153+
dcmbytes_full = dim.read()
1154+
dcmext = Nifti1DicomExtension(2,dcmbytes_full)
1155+
assert_equal(dcmext.get_content().PatientID, 'NiPy')
1156+
assert_equal(dcmext.get_content().file_meta.TransferSyntaxUID,encoding)
1157+
1158+
11471159
class TestNifti1General(object):
11481160
""" Test class to test nifti1 in general
11491161

0 commit comments

Comments
 (0)