Message307529
I'm not sure this is a duplicate of issue29094. That issue includes random data at the start of the file, while this issue uses the 'ab' mode solely for a creating the file if it doesn't exist (and thus is either empty or already a valid zip file). It's not clear to me why 'wb' should work but not 'ab' if the file was empty/missing to begin with.
[Windows 10, Python 3.6.3, 64 bit] still has the same problem.
Here's a more complete test case, starting with no existing files:
from zipfile import ZipFile
# Append mode: v
with open('file.zip', 'ab') as f:
with ZipFile(f, 'a') as zip:
zip.writestr('file.txt', 'contents')
with open('file.zip', 'rb') as f:
with ZipFile(f, 'r') as zip:
print(zip.read('file.txt'))
# Fails with "zipfile.BadZipFile: Bad magic number for file header"
# Write mode: v
with open('file.zip', 'wb') as f:
with ZipFile(f, 'a') as zip:
zip.writestr('file.txt', 'contents')
with open('file.zip', 'rb') as f:
with ZipFile(f, 'r') as zip:
print(zip.read('file.txt'))
# Works. |
|
Date |
User |
Action |
Args |
2017-12-04 00:25:16 | BoppreH | set | recipients:
+ BoppreH, paul.moore, tim.golden, zach.ware, serhiy.storchaka, steve.dower |
2017-12-04 00:25:16 | BoppreH | set | messageid: <1512347116.02.0.213398074469.issue30213@psf.upfronthosting.co.za> |
2017-12-04 00:25:16 | BoppreH | link | issue30213 messages |
2017-12-04 00:25:15 | BoppreH | create | |
|