mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
132 lines
2.5 KiB
Python
132 lines
2.5 KiB
Python
import zlib
|
|
import json
|
|
|
|
data = {
|
|
"name": "John Doe",
|
|
"age": 30,
|
|
"cars": [
|
|
{"model": "BMW 230", "mpg": 27.5},
|
|
{"model": "Ford Edge", "mpg": 24.1}
|
|
],
|
|
"data": [
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
[1, 231],
|
|
[2, 232],
|
|
[3, 233],
|
|
[4, 234],
|
|
[5, 235],
|
|
[6, 236],
|
|
[7, 237],
|
|
[8, 238],
|
|
[9, 239],
|
|
[10, 240],
|
|
[11, 241],
|
|
[12, 242],
|
|
[13, 243],
|
|
[14, 244],
|
|
]
|
|
}
|
|
|
|
# Convert the data to a JSON string
|
|
json_str = json.dumps(data)
|
|
|
|
# Original data
|
|
original_data = json_str.encode()
|
|
# print("size of original data: ", len(original_data))
|
|
|
|
# Compress the data
|
|
compressed_data = zlib.compress(original_data, level=1)
|
|
|
|
# Decompress the data
|
|
decompressed_data = zlib.decompress(compressed_data)
|
|
|
|
# Check if the decompressed data is the same as the original data
|
|
assert decompressed_data == original_data, 'Decompressed data does not match original data'
|
|
|
|
# print("size of compressed data: ", len(compressed_data))
|
|
|
|
print("PASS")
|