Skip to content

Commit bedd23d

Browse files
authored
Use backport.zstd instead of zstandard (#1962)
1 parent dcca90f commit bedd23d

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

fsspec/compression.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Helper functions for a standard streaming compression API"""
22

3+
import sys
34
from zipfile import ZipFile
45

56
import fsspec.utils
@@ -155,26 +156,14 @@ def _fetch_range(self, start, end):
155156
pass
156157

157158
try:
158-
# zstd in the standard library for python >= 3.14
159-
from compression.zstd import ZstdFile
160-
161-
register_compression("zstd", ZstdFile, "zst")
159+
if sys.version_info >= (3, 14):
160+
from compression import zstd
161+
else:
162+
from backports import zstd
162163

164+
register_compression("zstd", zstd.ZstdFile, "zst")
163165
except ImportError:
164-
try:
165-
import zstandard as zstd
166-
167-
def zstandard_file(infile, mode="rb"):
168-
if "r" in mode:
169-
cctx = zstd.ZstdDecompressor()
170-
return cctx.stream_reader(infile)
171-
else:
172-
cctx = zstd.ZstdCompressor(level=10)
173-
return cctx.stream_writer(infile)
174-
175-
register_compression("zstd", zstandard_file, "zst")
176-
except ImportError:
177-
pass
166+
pass
178167

179168

180169
def available_compressions():

fsspec/tests/test_compression.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pathlib
2+
import sys
23

34
import pytest
45

@@ -95,11 +96,10 @@ def test_zstd_compression(tmpdir):
9596
"""Infer zstd compression for .zst files if zstandard is available."""
9697
tmp_path = pathlib.Path(str(tmpdir))
9798

98-
try:
99-
# zstd in the standard library for python >= 3.14
99+
if sys.version_info >= (3, 14):
100100
from compression import zstd
101-
except ImportError:
102-
zstd = pytest.importorskip("zstandard")
101+
else:
102+
zstd = pytest.importorskip("backports.zstd")
103103

104104
tmp_path.mkdir(exist_ok=True)
105105

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ test_full = [
117117
'tqdm',
118118
'urllib3',
119119
'zarr',
120-
'zstandard; python_version < "3.14"',
120+
'backports.zstd; python_version < "3.14"',
121121
]
122122
test_downstream = [
123123
"dask[dataframe,test]",

0 commit comments

Comments
 (0)