Skip to content

Commit b0c23fb

Browse files
committed
Add .zst support to save api and AFNI/MINC formats
1 parent 7d03aa4 commit b0c23fb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

nibabel/brikhead.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ class AFNIImage(SpatialImage):
494494
makeable = False
495495
rw = False
496496
ImageArrayProxy = AFNIArrayProxy
497+
try: # If pyzstd installed., add .zst suffix
498+
import pyzstd
499+
_compressed_suffixes = (*_compressed_suffixes, '.zst')
500+
except ImportError:
501+
pass
497502

498503
@classmethod
499504
def from_file_map(klass, file_map, *, mmap=True, keep_file_open=None):

nibabel/loadsave.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
from .arrayproxy import is_proxy
2020
from .deprecated import deprecate_with_version
2121

22+
_compressed_suffixes = ('.gz', '.bz2')
23+
try: # If pyzstd installed., add .zst suffix
24+
import pyzstd
25+
_compressed_suffixes = (*_compressed_suffixes, '.zst')
26+
except ImportError:
27+
pass
2228

2329
def load(filename, **kwargs):
2430
r""" Load file given filename, guessing at file type
@@ -103,7 +109,7 @@ def save(img, filename):
103109
return
104110

105111
# Be nice to users by making common implicit conversions
106-
froot, ext, trailing = splitext_addext(filename, ('.gz', '.bz2'))
112+
froot, ext, trailing = splitext_addext(filename, _compressed_suffixes)
107113
lext = ext.lower()
108114

109115
# Special-case Nifti singles and Pairs

nibabel/minc1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ class Minc1Image(SpatialImage):
317317
valid_exts = ('.mnc',)
318318
files_types = (('image', '.mnc'),)
319319
_compressed_suffixes = ('.gz', '.bz2')
320+
try: # If pyzstd installed., add .zst suffix
321+
import pyzstd
322+
_compressed_suffixes = (*_compressed_suffixes, '.zst')
323+
except ImportError:
324+
pass
320325

321326
makeable = True
322327
rw = False

0 commit comments

Comments
 (0)