Skip to content

Commit 64a50fa

Browse files
committed
fix zstd decompression for python 3.13+ stdlib compression.zstd
compression.zstd uses decompress() directly, while python-zstandard uses ZstdDecompressor().stream_reader(). use hasattr to pick the right api at call time.
1 parent e9b63e5 commit 64a50fa

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

util/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ def unzstd(contents):
194194
""" unzstd contents in memory and return the data
195195
"""
196196
try:
197-
zstddata = zstd.ZstdDecompressor().stream_reader(contents).read()
198-
return zstddata
199-
except zstd.ZstdError as e:
197+
if hasattr(zstd, 'decompress'):
198+
return zstd.decompress(contents)
199+
return zstd.ZstdDecompressor().stream_reader(contents).read()
200+
except (zstd.ZstdError, Exception) as e:
200201
error_message(text=f'zstd: {e}')
201202

202203

0 commit comments

Comments
 (0)