惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
S
Securelist
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
AI
AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Schneier on Security
Schneier on Security
Attack and Defense Labs
Attack and Defense Labs
Vercel News
Vercel News
腾讯CDC
Google DeepMind News
Google DeepMind News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
量子位
S
Schneier on Security
Hacker News: Ask HN
Hacker News: Ask HN
Cyberwarzone
Cyberwarzone
S
Security Affairs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
T
Tenable Blog
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
W
WeLiveSecurity
N
News | PayPal Newsroom
P
Proofpoint News Feed
O
OpenAI News
C
CERT Recently Published Vulnerability Notes
B
Blog
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Spread Privacy
Spread Privacy

Bing's Blog

git-cm:在终端里用 LLM 生成 commit message Token Tracker - 追踪 Coding Agent 的 Token 使用情况 AI Coding 工具的实践经验 2025年终总结 行车记录仪视频拼接 生成文章摘要 DMA拼接 2024年终总结 二维数据可视化工具-painter 对ToB和ToC的感受 C++闭包二 轻量级参数解析库-tiny_cmdline C++标签派发技术
Base64压缩
bing · 2025-04-17 · via Bing's Blog

首先, 明确base64并不是一个压缩算法. 但是在某些场景我们可以使用其编码特性达到压缩的效果.

如下demo展示的一种应用场景:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import base64
import json

origin_data = {
    "config1": 1,
    "config2": 2,
    "calibration_list": [
        0.465485,
        0.693291,
        0.914242,
        0.438485,
        0.621781,
        0.148442,
        0.536921,
        0.789463,
        0.069955,
        0.649050,
    ]
}

print("before compress", len(json.dumps(origin_data)))

compress_data = origin_data
# contact calibration_list as a bytes string and then base64 encode
calibration_bytes = b"".join(
    [bytes([int(x * 255)]) for x in origin_data["calibration_list"]]
)
compress_data["calibration_list"] = base64.b64encode(calibration_bytes).decode("utf-8")
print("after compress", len(json.dumps(compress_data)))

输出:

1
2
before compress 149
after compress 68

config1config2一般是需要人工调整的配置, 所以需要明文表示. calibration_list一般由机器生成和阅读, 所以不太关注其可读性.

这两种配置又期望用同一个配置文件管理, 那么通过将calibration_list转换为二进制数据, 然后base64编码, 这样既使得配置文件可以以文本方式解析, 又相对减少了文件大小, 在一些空间/传输速率敏感的场合适用.

以上demo只是一种应用场景, 细节需要具体问题具体分析.

base64编码后的大小约等于原大小的4/3(增大了空间), 压缩比例和base64编码的对象+精度需求相关. 以json格式+7位精度需求的32bit浮点数组为例, 一个数字表示至少需要8B(1B逗号+7B数字), 但是base64编码后只需要6B. 这种情况下压缩率75%.