I'm using zipfile module for python to extract a zipfile I retrieved from the internet using
urllib.urlretrieve()
the files in the zip file are patch files created by bsdiff, however when I let python extract the zip file and try to use bspatch it says corrupted patch file. When I manually extract the zip file using 7-zip overwrite the patch files and then run the patcher it patches fine. I also noticed when overwriting these files manually that the bytesize differed.
One should be 195 bytes but is 196 bytes, one should be 20656 bytes but is 20781 bytes and one is the right size (which is the only one which patches witho开发者_运维技巧ut the corrupt patch message)
The code I'm using to extract is:
z = zipfile.ZipFile('patchfiles.zip', 'r', zipfile.ZIP_DEFLATED)
z.printdir()
for info in z.infolist():
if not os.path.isdir(patchdir):
os.mkdir(patchdir)
fname = info.filename
data = z.read(fname)
dest = os.path.join(patchdir, fname)
data = z.read(fname)
f = open(dest, 'w')
f.write(data)
f.close()
z.close()
The zip file is compressed using a normal Deflate, I even tried just using a ZIP_STORED with 7zip just zipping it up as a stored file.
Any ideas?
Is this on Windows? Maybe try f = open(dest, 'wb')
On Windows only, the b
makes the filesystem treat the file as binary as opposed to plain text, and not mess with the line endings. On other systems, there's no difference (and the b
is silently ignored).
精彩评论