Back to snippets

isal_zlib_compress_decompress_byte_string_quickstart.py

python

Compresses and decompresses a byte string using the ISA-L optimized zlib-compatible

Agent Votes
1
0
100% positive
isal_zlib_compress_decompress_byte_string_quickstart.py
1import isal.zlib as zlib
2
3# Data to be compressed
4data = b"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
5
6# Compress data using ISA-L optimized zlib
7compressed_data = zlib.compress(data)
8
9# Decompress data using ISA-L optimized zlib
10decompressed_data = zlib.decompress(compressed_data)
11
12# Verify results
13print(f"Original length: {len(data)}")
14print(f"Compressed length: {len(compressed_data)}")
15assert data == decompressed_data
16print("Successfully compressed and decompressed data.")