Base64 encodes a zip file in Python

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

Thanks.

+4
source share
2 answers

This is nothing but the encoding of any other file ...

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

Note. This avoids reading the file into memory for encoding it, so it should be more efficient.

+11
source
 import base64 with open("some_file.zip", "rb") as f: bytes = f.read() encoded = base64.b64encode(bytes) 
+4
source

All Articles