hutool.core.util.base64_util¶
Base64 编解码工具类
Module Contents¶
Classes¶
Base64 编解码工具类。 |
API¶
- class hutool.core.util.base64_util.Base64Util¶
Base64 编解码工具类。
- static encode(data)¶
Base64 编码。
- 参数:
data – 待编码的 bytes 或 str
- 返回:
Base64 编码的 bytes
- static encode_str(s: str, charset: str = 'utf-8') str¶
将字符串进行 Base64 编码,返回字符串。
- 参数:
s – 待编码的字符串
charset – 字符集,默认
"utf-8"
- 返回:
Base64 编码字符串
- static encode_url_safe(data) bytes¶
URL 安全的 Base64 编码。
- 参数:
data – 待编码的 bytes 或 str
- 返回:
URL 安全的 Base64 编码 bytes
- static encode_without_padding(data) bytes¶
Base64 编码(不含填充字符
=)。- 参数:
data – 待编码的 bytes 或 str
- 返回:
不含填充的 Base64 编码 bytes
- static encode_from_file(file_path: str) str¶
读取文件并进行 Base64 编码。
- 参数:
file_path – 文件路径
- 返回:
Base64 编码字符串
- static encode_from_stream(stream) str¶
从流中读取并进行 Base64 编码。
- 参数:
stream – 可读的二进制流
- 返回:
Base64 编码字符串
- static decode(base64_str)¶
Base64 解码。
- 参数:
base64_str – Base64 编码的字符串或 bytes
- 返回:
解码后的 bytes
- static decode_str(base64_str: str, charset: str = 'utf-8') str¶
Base64 解码为字符串。
- 参数:
base64_str – Base64 编码字符串
charset – 字符集,默认
"utf-8"
- 返回:
解码后的字符串
- static decode_str_gbk(base64_str: str) str¶
Base64 解码为 GBK 字符串。
- 参数:
base64_str – Base64 编码字符串
- 返回:
GBK 解码后的字符串
- static decode_to_file(base64_str: str, file_path: str) None¶
Base64 解码并写入文件。
- 参数:
base64_str – Base64 编码字符串
file_path – 目标文件路径
- static is_base64(s: str) bool¶
判断字符串是否为有效的 Base64 编码。
- 参数:
s – 待检查的字符串
- 返回:
是否为有效 Base64