Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions fsspec/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,26 @@ def _fetch_range(self, start, end):
pass

try:
import zstandard as zstd
# zstd in the standard library for python >= 3.14
from compression.zstd import ZstdFile

def zstandard_file(infile, mode="rb"):
if "r" in mode:
cctx = zstd.ZstdDecompressor()
return cctx.stream_reader(infile)
else:
cctx = zstd.ZstdCompressor(level=10)
return cctx.stream_writer(infile)
register_compression("zstd", ZstdFile, "zst")

register_compression("zstd", zstandard_file, "zst")
except ImportError:
pass
try:
import zstandard as zstd

def zstandard_file(infile, mode="rb"):
if "r" in mode:
cctx = zstd.ZstdDecompressor()
return cctx.stream_reader(infile)
else:
cctx = zstd.ZstdCompressor(level=10)
return cctx.stream_writer(infile)

register_compression("zstd", zstandard_file, "zst")
except ImportError:
pass


def available_compressions():
Expand Down
6 changes: 5 additions & 1 deletion fsspec/tests/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def test_zstd_compression(tmpdir):
"""Infer zstd compression for .zst files if zstandard is available."""
tmp_path = pathlib.Path(str(tmpdir))

zstd = pytest.importorskip("zstandard")
try:
# zstd in the standard library for python >= 3.14
from compression import zstd
except ImportError:
zstd = pytest.importorskip("zstandard")

tmp_path.mkdir(exist_ok=True)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ test_full = [
'tqdm',
'urllib3',
'zarr',
'zstandard',
'zstandard; python_version < "3.14"',
]
test_downstream = [
"dask[dataframe,test]",
Expand Down
Loading