import sys
# In Python 3.13, this import would fail and require 'pip install zstandard'
# In Python 3.14, this module is part of the standard library (PEP 784)
try:
    import zstd
except ImportError:
    print("\n--- WARNING: Running on 3.13 or earlier. Zstandard import failed. ---")
    print("In Python 3.14, 'import zstd' is part of the Standard Library, no 'pip install' needed.")
    sys.exit(1)

print("--- Python 3.14 Standard Library Zstandard Compression ---")
print("Benefit: High-speed, high-ratio compression without external dependencies.")

data = b"HTTP/1.1 200 OK\nContent-Type: application/json\n\n" * 1000 
data += b"A highly repetitive log line that compresses very well." * 500

# 1. Compression
compressed_data = zstd.compress(data)

# 2. Decompression
decompressed_data = zstd.decompress(compressed_data)

# 3. Validation and Metrics
print(f"\nOriginal Size: {len(data):,} bytes")
print(f"Compressed Size: {len(compressed_data):,} bytes")
print(f"Compression Ratio: {len(data) / len(compressed_data):.2f}x")

assert data == decompressed_data
print("\nSuccess: Data integrity verified after Zstandard processing.")
