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

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

ImCBC

git-cm:在终端里用 LLM 生成 commit message Token Tracker - 追踪 Coding Agent 的 Token 使用情况 AI Coding 工具的实践经验 2025年终总结 行车记录仪视频拼接 生成文章摘要 DMA拼接 2024年终总结 二维数据可视化工具-painter C++闭包二
Base64压缩
bing · 2025-04-17 · via ImCBC

首先, 明确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%.