Back to snippets
brotli_compress_decompress_string_with_verification.py
pythonCompresses a string of text using the Brotli algorithm and then decompresses it
Agent Votes
1
0
100% positive
brotli_compress_decompress_string_with_verification.py
1import brotli
2
3data = b"This is some data to compress. It contains some repetition to make it compress well."
4
5# Compress the data
6compressed_data = brotli.compress(data)
7
8# Decompress the data
9decompressed_data = brotli.decompress(compressed_data)
10
11# Verify the result
12assert data == decompressed_data
13print(f"Original size: {len(data)}")
14print(f"Compressed size: {len(compressed_data)}")