-
Notifications
You must be signed in to change notification settings - Fork 101
Add streaming decompression for ZSTD_CONTENTSIZE_UNKNOWN case #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
d-v-b
merged 15 commits into
zarr-developers:main
from
mkitti:mkitti-zstd-stream-decompress
Jul 10, 2025
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d04e536
Add streaming decompression for ZSTD_CONTENTSIZE_UNKNOWN case
mkitti 1096df7
Add tests and documentation for streaming Zstd
mkitti a903ee5
Add better tests from numcodecs.js
mkitti ccddf41
Merge branch 'main' into mkitti-zstd-stream-decompress
mkitti d3049ca
Adapt zstd.pyx streaming for Py_buffer
mkitti 834b74d
Formatting with ruff
mkitti a2c7fb0
Fix zstd comparison of different signedness
mkitti 0dcffe6
Undo change to unrelated test
mkitti 4edc73a
Add zstd cli tests
mkitti 16cc9b3
Test Zstd against pyzstd
mkitti 308caf3
Apply ruff
mkitti 1f5670f
Fix zstd tests, coverage
mkitti dcf2989
Make imports not optional
mkitti 78f26fc
Add EndlessZstdDecompressor tests
mkitti 313d534
Add docstrings to test_pyzstd.py
mkitti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Check Zstd against pyzstd package | ||
|
||
import numpy as np | ||
import pytest | ||
import pyzstd | ||
|
||
from numcodecs.zstd import Zstd | ||
|
||
test_data = [ | ||
b"Hello World!", | ||
np.arange(113).tobytes(), | ||
np.arange(10, 15).tobytes(), | ||
np.random.randint(3, 50, size=(53,), dtype=np.uint16).tobytes(), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("input", test_data) | ||
def test_pyzstd_simple(input): | ||
z = Zstd() | ||
assert z.decode(pyzstd.compress(input)) == input | ||
assert pyzstd.decompress(z.encode(input)) == input | ||
|
||
|
||
@pytest.mark.xfail | ||
@pytest.mark.parametrize("input", test_data) | ||
def test_pyzstd_simple_multiple_frames_decode(input): | ||
z = Zstd() | ||
assert z.decode(pyzstd.compress(input) * 2) == input * 2 | ||
|
||
|
||
@pytest.mark.parametrize("input", test_data) | ||
def test_pyzstd_simple_multiple_frames_encode(input): | ||
z = Zstd() | ||
assert pyzstd.decompress(z.encode(input) * 2) == input * 2 | ||
|
||
|
||
@pytest.mark.parametrize("input", test_data) | ||
def test_pyzstd_streaming(input): | ||
pyzstd_c = pyzstd.ZstdCompressor() | ||
pyzstd_d = pyzstd.ZstdDecompressor() | ||
pyzstd_e = pyzstd.EndlessZstdDecompressor() | ||
z = Zstd() | ||
|
||
d_bytes = input | ||
pyzstd_c.compress(d_bytes) | ||
c_bytes = pyzstd_c.flush() | ||
assert z.decode(c_bytes) == d_bytes | ||
assert pyzstd_d.decompress(z.encode(d_bytes)) == d_bytes | ||
|
||
# Test multiple streaming frames | ||
assert z.decode(c_bytes * 2) == pyzstd_e.decompress(c_bytes * 2) | ||
assert z.decode(c_bytes * 3) == pyzstd_e.decompress(c_bytes * 3) | ||
assert z.decode(c_bytes * 4) == pyzstd_e.decompress(c_bytes * 4) | ||
assert z.decode(c_bytes * 5) == pyzstd_e.decompress(c_bytes * 5) | ||
assert z.decode(c_bytes * 7) == pyzstd_e.decompress(c_bytes * 7) | ||
assert z.decode(c_bytes * 11) == pyzstd_e.decompress(c_bytes * 11) | ||
assert z.decode(c_bytes * 13) == pyzstd_e.decompress(c_bytes * 13) | ||
assert z.decode(c_bytes * 99) == pyzstd_e.decompress(c_bytes * 99) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ test = [ | |
"coverage", | ||
"pytest", | ||
"pytest-cov", | ||
"pyzstd" | ||
] | ||
test_extras = [ | ||
"importlib_metadata", | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.