Set AESZipFile encryption default to WZ_AES
Hi @danifus 👋 , I was testing out pyzipper and ran into some unexpected behavior when writing a zipfile. e.g.,
with pyzipper.AESZipFile("archive.zip", "w") as archive:
archive.setpassword(b"password")
with archive.open("file.txt", "w") as file:
...
The above resulted in this traceback:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "./.venv/lib/python3.9/site-packages/pyzipper/zipfile.py", line 2006, in open
return self._open_to_write(zinfo, force_zip64=force_zip64, pwd=pwd)
File "./.venv/lib/python3.9/site-packages/pyzipper/zipfile.py", line 2049, in _open_to_write
encrypter.update_zipinfo(zinfo)
AttributeError: 'NoneType' object has no attribute 'update_zipinfo'
This was simply caused by my not specifying the encryption in the constructor, or via the setencryption method. However, it would seem sensible that AESZipFile would default to encryption=WZ_AES? Is there a reason why this shouldn't be the default? Thanks.
Hi,
That's a good idea. Thanks for the patch! I'll need to adjust some of the tests before I can merge it
Just a thought.. it's a good idea if the encryption setting only applies when a password is set. Meaning, AESZipFile still needs to act like python's zipfile.ZipFile if no password is set to still be a drop in replacement.
While I'm commenting... curious why pyzipper changes have not been merged (PR) into Python's core zipfile?