45
45
_write_data ,
46
46
_ftype4scaled_finite ,
47
47
)
48
- from ..openers import Opener , BZ2File
48
+ from ..openers import Opener , BZ2File , ZstdFile
49
49
from ..casting import (floor_log2 , type_info , OK_FLOATS , shared_range )
50
50
51
51
from ..deprecator import ExpiredDeprecationError
@@ -70,7 +70,8 @@ def test__is_compressed_fobj():
70
70
with InTemporaryDirectory ():
71
71
for ext , opener , compressed in (('' , open , False ),
72
72
('.gz' , gzip .open , True ),
73
- ('.bz2' , BZ2File , True )):
73
+ ('.bz2' , BZ2File , True ),
74
+ ('.zst' , ZstdFile , True )):
74
75
fname = 'test.bin' + ext
75
76
for mode in ('wb' , 'rb' ):
76
77
fobj = opener (fname , mode )
@@ -88,12 +89,12 @@ def make_array(n, bytes):
88
89
arr .flags .writeable = True
89
90
return arr
90
91
91
- # Check whether file, gzip file, bz2 file reread memory from cache
92
+ # Check whether file, gzip file, bz2, zst file reread memory from cache
92
93
fname = 'test.bin'
93
94
with InTemporaryDirectory ():
94
95
for n , opener in itertools .product (
95
96
(256 , 1024 , 2560 , 25600 ),
96
- (open , gzip .open , BZ2File )):
97
+ (open , gzip .open , BZ2File , ZstdFile )):
97
98
in_arr = np .arange (n , dtype = dtype )
98
99
# Write array to file
99
100
fobj_w = opener (fname , 'wb' )
@@ -230,7 +231,7 @@ def test_array_from_file_openers():
230
231
dtype = np .dtype (np .float32 )
231
232
in_arr = np .arange (24 , dtype = dtype ).reshape (shape )
232
233
with InTemporaryDirectory ():
233
- for ext , offset in itertools .product (('' , '.gz' , '.bz2' ),
234
+ for ext , offset in itertools .product (('' , '.gz' , '.bz2' , '.zst' ),
234
235
(0 , 5 , 10 )):
235
236
fname = 'test.bin' + ext
236
237
with Opener (fname , 'wb' ) as out_buf :
@@ -253,7 +254,7 @@ def test_array_from_file_reread():
253
254
with InTemporaryDirectory ():
254
255
for shape , opener , dtt , order in itertools .product (
255
256
((64 ,), (64 , 65 ), (64 , 65 , 66 )),
256
- (open , gzip .open , bz2 .BZ2File , BytesIO ),
257
+ (open , gzip .open , bz2 .BZ2File , ZstdFile , BytesIO ),
257
258
(np .int16 , np .float32 ),
258
259
('F' , 'C' )):
259
260
n_els = np .prod (shape )
@@ -901,7 +902,7 @@ def test_write_zeros():
901
902
def test_seek_tell ():
902
903
# Test seek tell routine
903
904
bio = BytesIO ()
904
- in_files = bio , 'test.bin' , 'test.gz' , 'test.bz2'
905
+ in_files = bio , 'test.bin' , 'test.gz' , 'test.bz2' , 'test.zst'
905
906
start = 10
906
907
end = 100
907
908
diff = end - start
@@ -920,9 +921,12 @@ def test_seek_tell():
920
921
fobj .write (b'\x01 ' * start )
921
922
assert fobj .tell () == start
922
923
# Files other than BZ2Files can seek forward on write, leaving
923
- # zeros in their wake. BZ2Files can't seek when writing, unless
924
- # we enable the write0 flag to seek_tell
925
- if not write0 and in_file == 'test.bz2' : # Can't seek write in bz2
924
+ # zeros in their wake. BZ2Files can't seek when writing,
925
+ # unless we enable the write0 flag to seek_tell
926
+ # ZstdFiles also does not support seek forward on write
927
+ if (not write0 and
928
+ (in_file == 'test.bz2' or
929
+ in_file == 'test.zst' )): # Can't seek write in bz2, zst
926
930
# write the zeros by hand for the read test below
927
931
fobj .write (b'\x00 ' * diff )
928
932
else :
@@ -946,7 +950,7 @@ def test_seek_tell():
946
950
# Check we have the expected written output
947
951
with ImageOpener (in_file , 'rb' ) as fobj :
948
952
assert fobj .read () == b'\x01 ' * start + b'\x00 ' * diff + b'\x02 ' * tail
949
- for in_file in ('test2.gz' , 'test2.bz2' ):
953
+ for in_file in ('test2.gz' , 'test2.bz2' , 'test2.zst' ):
950
954
# Check failure of write seek backwards
951
955
with ImageOpener (in_file , 'wb' ) as fobj :
952
956
fobj .write (b'g' * 10 )
0 commit comments