base64

import base64

file_path = r'xxx'
with open(file_path, 'rb') as f:
data = f.read()
b64_byte = base64.b64encode(data) # 使用b64对类字节对象进行编码,但是结果还是byte类型
b64_str = b64_byte.decode('utf-8')
print(f'base64_data:\n{b64_str}\ntype:\n{type(b64_str)}')

re_data = base64.b64decode(b64_str) # 解码为二进制数据
print(f're_data:\n{re_data}\ntype:{type(re_data)}')
posted @ 2023-12-04 11:15  tslam  阅读(5)  评论(0编辑  收藏  举报