base64用Python编码一个zip文件 [英] base64 encode a zip file in Python

查看:513
本文介绍了base64用Python编码一个zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我一些关于如何在python中将zip文件编码为base64的建议吗?有一些有关如何使用模块base64在Python中编码文件的示例,但是我还没有找到有关zipfile编码的任何资源.

Can someone give me some advice on how to encode a zip file into base64 in Python? There are examples on how to encode files in Python using the module base64, but I have not found any resources on zipfile encoding.

谢谢.

推荐答案

这与对任何其他文件进行编码没有区别...

This is no different than encoding any other file...

import base64

with open('input.zip', 'rb') as fin, open('output.zip.b64', 'w') as fout:
    base64.encode(fin, fout)

注意:这避免了将文件读入内存以对其进行编码,因此应该更有效.

NB: This avoids reading the file into memory to encode it, so should be more efficient.

这篇关于base64用Python编码一个zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆