Skip to content

Commit 5f9d771

Browse files
authored
add support for decompressing blocks without the snappy magic header (#268)
1 parent 03d21d3 commit 5f9d771

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cterasdk/direct/decompressor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ def decompress(compressed_block):
77
"""
88
Decompress a Block.
99
10+
:param bytes block: Compressed Block
11+
:returns: Decompressed Block
12+
:rtype: bytes
13+
"""
14+
return decompress_with_magic_header(compressed_block) \
15+
if compressed_block.startswith(b'\x82SNAPPY\x00') else decompress_without_magic_header(compressed_block)
16+
17+
18+
def decompress_with_magic_header(compressed_block):
19+
"""
20+
Decompress a Block.
21+
1022
:param bytes block: Compressed Block
1123
:returns: Decompressed Block
1224
:rtype: bytes
@@ -26,3 +38,14 @@ def decompress(compressed_block):
2638
return decompressed_block
2739
except snappy.UncompressError:
2840
raise DirectIOError()
41+
42+
43+
def decompress_without_magic_header(compressed_block):
44+
"""
45+
Decompress a Block.
46+
47+
:param bytes compressed_block: Compressed Block
48+
:returns: Decompressed Block
49+
:rtype: bytes
50+
"""
51+
return snappy.uncompress(compressed_block[:compressed_block.rfind(b'EOF') + 3])

0 commit comments

Comments
 (0)