Skip to content

Commit e30e632

Browse files
committed
Remove header when decompressing
1 parent d951fd0 commit e30e632

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/meta_memcache/serializer.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class ZstdSerializer(BaseSerializer):
7272
BINARY = 16
7373
ZSTD_COMPRESSED = 32
7474

75-
ZSTD_MAGIC = b"(\xb5/\xfd"
7675
DEFAULT_PICKLE_PROTOCOL = 5
7776
DEFAULT_COMPRESSION_LEVEL = 9
7877
DEFAULT_COMPRESSION_THRESHOLD = 128
@@ -174,10 +173,10 @@ def _compress(self, key: Key, data: bytes) -> Tuple[bytes, int]:
174173
return zlib.compress(data), self.ZLIB_COMPRESSED
175174

176175
def _decompress(self, data: bytes) -> bytes:
177-
dict_id = zstd.get_frame_parameters(self.ZSTD_MAGIC + data).dict_id
178-
if decompressor := self._zstd_decompressors.get(dict_id):
176+
params = zstd.get_frame_parameters(data, format=zstd.FORMAT_ZSTD1_MAGICLESS)
177+
if decompressor := self._zstd_decompressors.get(params.dict_id):
179178
return decompressor.decompress(data)
180-
raise ValueError(f"Unknown dictionary id: {dict_id}")
179+
raise ValueError(f"Unknown dictionary id: {params.dict_id}")
181180

182181
def _should_compress(self, key: Key, data: bytes) -> bool:
183182
data_len = len(data)

tests/serializer_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_compression_dict(compressor: zstd.ZstdCompressor) -> int:
3434

3535

3636
def get_data_compression_dict(data: bytes) -> int:
37-
return zstd.get_frame_parameters(ZstdSerializer.ZSTD_MAGIC + data).dict_id
37+
return zstd.get_frame_parameters(data, format=zstd.FORMAT_ZSTD1_MAGICLESS).dict_id
3838

3939

4040
def test_zstd_serializer_initialization(

0 commit comments

Comments
 (0)