Brotli是一種開源的新型壓縮算法堂淡,壓縮效率性能優(yōu)秀教馆。通過壓縮后進(jìn)行網(wǎng)絡(luò)數(shù)據(jù)傳輸逊谋,可以大大減少網(wǎng)絡(luò)負(fù)載,加快數(shù)據(jù)傳輸速度土铺。
python中可以使用pip install Brotli安裝br庫胶滋,目前版本為1.0.9
pip list
......
Brotli 1.0.9
簡單的使用br.py,測試如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import brotli
data = "Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default."
print("ori_data:\n%s" % data)
print("data size: %s" % len(data))
compress_data = brotli.compress(data.encode('utf-8'))
print("compress size: %s" % len(compress_data))
decompress_data = brotli.decompress(compress_data)
print("decompress:\n%s" % decompress_data.decode('utf-8'))
執(zhí)行br.py結(jié)果:
# python br.py
ori_data:
Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default.
data size: 201
compress size: 107
decompress:
Bash is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). Bash can be configured to be POSIX-conformant by default.
可以看出長度為201的字符串悲敷,壓縮后長度僅為107究恤,壓縮比優(yōu)秀。