使用brotli解压缩

Brotli是一种开源的新型压缩算法,压缩效率性能优秀。通过压缩后进行网络数据传输,可以大大减少网络负载,加快数据传输速度。
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'))

执行br.py结果:

# 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,压缩比优秀。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容