|
30 | 30 | 'complex64':'single','longlong':'int64','ulonglong':'uint64', |
31 | 31 | 'csingle':'single','cdouble':'double'}; |
32 | 32 |
|
33 | | -_zipper=['zlib','gzip','lzma','lz4','base64']; |
| 33 | +_zipper=['zlib','gzip','lzma','lz4','blosc2blosclz','blosc2lz4','blosc2lz4hc','blosc2zlib','blosc2zstd','base64']; |
34 | 34 |
|
35 | 35 | ##==================================================================================== |
36 | 36 | ## Python to JData encoding function |
@@ -60,6 +60,11 @@ def encode(d, opt={}): |
60 | 60 | import lz4.frame |
61 | 61 | except ImportError: |
62 | 62 | raise Exception('JData', 'you must install "lz4" module to compress with this format') |
| 63 | + elif(opt['compression'].startswith('blosc2')): |
| 64 | + try: |
| 65 | + import blosc2 |
| 66 | + except ImportError: |
| 67 | + raise Exception('JData', 'you must install "blosc2" module to compress with this format') |
63 | 68 |
|
64 | 69 | if isinstance(d, float): |
65 | 70 | if(np.isnan(d)): |
@@ -104,21 +109,30 @@ def encode(d, opt={}): |
104 | 109 | newobj['_ArrayZipData_']=zlib.compress(newobj['_ArrayZipData_'],zlib.MAX_WBITS|32); |
105 | 110 | elif(opt['compression']=='lzma'): |
106 | 111 | try: |
107 | | - try: |
108 | | - import lzma |
109 | | - except ImportError: |
110 | | - from backports import lzma |
111 | 112 | newobj['_ArrayZipData_']=lzma.compress(newobj['_ArrayZipData_'],lzma.FORMAT_ALONE); |
112 | 113 | except Exception: |
113 | 114 | print('you must install "lzma" module to compress with this format, ignoring') |
114 | 115 | pass |
115 | 116 | elif(opt['compression']=='lz4'): |
116 | 117 | try: |
117 | | - import lz4.frame |
118 | 118 | newobj['_ArrayZipData_']=lz4.frame.compress(newobj['_ArrayZipData_']); |
119 | 119 | except ImportError: |
120 | 120 | print('you must install "lz4" module to compress with this format, ignoring') |
121 | 121 | pass |
| 122 | + elif(opt['compression'].startswith('blosc2')): |
| 123 | + try: |
| 124 | + BLOSC2CODEC={ |
| 125 | + 'blosc2blosclz': blosc2.Codec.BLOSCLZ, 'blosc2lz4': blosc2.Codec.LZ4, |
| 126 | + 'blosc2lz4hc': blosc2.Codec.LZ4HC, 'blosc2zlib': blosc2.Codec.ZLIB, |
| 127 | + 'blosc2zstd': blosc2.Codec.ZSTD |
| 128 | + } |
| 129 | + blosc2nthread = 1 |
| 130 | + if('nthread' in opt): |
| 131 | + blosc2nthread = opt['nthread'] |
| 132 | + newobj['_ArrayZipData_']=blosc2.compress2(newobj['_ArrayZipData_'], compcode=BLOSC2CODEC[opt['compression']], typesize=d.dtype.itemsize, nthread=blosc2nthread) |
| 133 | + except ImportError: |
| 134 | + print('you must install "blosc2" module to compress with this format, ignoring') |
| 135 | + pass |
122 | 136 | if(('base64' in opt) and (opt['base64'])) or opt['compression']=='base64': |
123 | 137 | newobj['_ArrayZipData_']=base64.b64encode(newobj['_ArrayZipData_']); |
124 | 138 | newobj.pop('_ArrayData_'); |
@@ -178,6 +192,16 @@ def decode(d, opt={}): |
178 | 192 | except Exception: |
179 | 193 | print('Warning: you must install "lz4" module to decompress a data record in this file, ignoring') |
180 | 194 | pass |
| 195 | + elif(d['_ArrayZipType_'].startswith('blosc2')): |
| 196 | + try: |
| 197 | + import blosc2 |
| 198 | + blosc2nthread = 1 |
| 199 | + if('nthread' in opt): |
| 200 | + blosc2nthread = opt['nthread'] |
| 201 | + newobj=blosc2.decompress2(bytes(newobj), as_bytearray=False, nthread=blosc2nthread) |
| 202 | + except Exception: |
| 203 | + print('Warning: you must install "blosc2" module to decompress a data record in this file, ignoring') |
| 204 | + pass |
181 | 205 | newobj=np.fromstring(newobj,dtype=np.dtype(d['_ArrayType_'])).reshape(d['_ArrayZipSize_']); |
182 | 206 | if('_ArrayIsComplex_' in d and newobj.shape[0]==2): |
183 | 207 | newobj=newobj[0]+1j*newobj[1]; |
|
0 commit comments