I'm trying to compress a Excel BytesIO stream into a ZIP BytesIO stream but ValueError: stat: embedded null character in path
is called when I use write()
. I used pyzipper and pyminizip but neither worked well.
def __compress_excel__(self, excel_buffer):
zip_buffer = BytesIO()
password = b'password'
zip_buffer = pyzipper.AESZipFile(zip_stream, mode='w')
zip_buffer.setpassword(password)
zip_buffer.write(excel_buffer.getvalue())
return zip_buffer.getvalue()
I want to avoid using a temp file to do this. Regards.
UPDATE
Now thanks to martineau comments, Excel could be compressed now, but I have a new problem is that setpassword() from ZipFile doesn't work. A ZIP is created but when in uncompress it, no password is required.
def __compress_excel__(self, excel_buffer):
zip_stream = BytesIO()
password = b'password'
with ZipFile(zip_stream , mode='w') as zipf:
zipf.setpassword(password)
zipf.writestr('excel.xlsx', excel_buffer.getvalue())
return zip_stream.getvalue()
Regards