Skip to content

Commit 1096df7

Browse files
committed
Add tests and documentation for streaming Zstd
1 parent d04e536 commit 1096df7

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

docs/compression/zstd.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Zstd
77
.. autoattribute:: codec_id
88
.. automethod:: encode
99
.. automethod:: decode
10+
.. note::
11+
If the compressed data does not contain the decompressed size, streaming
12+
decompression will be used.
1013
.. automethod:: get_config
1114
.. automethod:: from_config
1215

docs/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Unreleased
1919

2020
Improvements
2121
~~~~~~~~~~~~
22+
* Add streaming decompression for ZSTD (:issue:`699`)
23+
By :user:`Mark Kittisopikul <mkitti>`.
2224
* Raise a custom `UnknownCodecError` when trying to retrieve an unavailable codec.
2325
By :user:`Cas Wognum <cwognum>`.
2426

numcodecs/tests/test_zstd.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,27 @@ def test_native_functions():
9090
assert Zstd.default_level() == 3
9191
assert Zstd.min_level() == -131072
9292
assert Zstd.max_level() == 22
93+
94+
95+
def test_streaming_decompression():
96+
codec = Zstd()
97+
# Bytes from streaming compression
98+
bytes_val = bytes(bytearray([
99+
40, 181, 47, 253, 0, 88, 97, 0, 0, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33,
100+
]))
101+
dec = codec.decode(bytes_val)
102+
assert dec == b'Hello World!'
103+
104+
bytes2 = bytes(bytearray([
105+
40, 181, 47, 253, 0, 88, 36, 2, 0, 164, 3, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
106+
83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108,
107+
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 1, 0, 58, 252, 223, 115, 5, 5, 76, 0, 0, 8,
108+
115, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 107, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 99, 1, 0, 252, 255, 57,
109+
16, 2, 76, 0, 0, 8, 91, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 83, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 75, 1,
110+
0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 67, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 117, 1, 0, 252, 255, 57, 16, 2, 76,
111+
0, 0, 8, 109, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 101, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 93, 1, 0, 252,
112+
255, 57, 16, 2, 76, 0, 0, 8, 85, 1, 0, 252, 255, 57, 16, 2, 76, 0, 0, 8, 77, 1, 0, 252, 255, 57, 16, 2, 77, 0, 0, 8,
113+
69, 1, 0, 252, 127, 29, 8, 1,
114+
]))
115+
dec2 = codec.decode(bytes2)
116+
assert dec2 == b'ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz' * 1024 * 32

numcodecs/zstd.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ def decompress(source, dest=None):
182182
Compressed data. Can be any object supporting the buffer protocol.
183183
dest : array-like, optional
184184
Object to decompress into. If the content size is unknown, the
185-
length of dest must match the decompressed size.
185+
length of dest must match the decompressed size. If the content size
186+
is unknown and dest is not provided, streaming decompression will be
187+
used.
186188
187189
Returns
188190
-------

0 commit comments

Comments
 (0)