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.
Thanks.
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.
import base64
with open("some_file.zip", "rb") as f:
bytes = f.read()
encoded = base64.b64encode(bytes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With