I’m using http://docs.python.org/library/zipfile.html to compress file into a zip. It works well but when extracting that file via my ubuntu (not in python, just right clicking file and then ‘Extract here’) file is truncated. My original file has ~167kb, extracted via ubuntu ~164kb (it’s csv file, so I miss few lines from the end of file).
Any suggestions?
Edit:
My code looks as follows:
try:
fp2 = zipfile.ZipFile(el.replace('.csv', '.zip'), 'w',
zipfile.ZIP_DEFLATED)
fp2.testzip()
fp2.write(el)
finally:
fp2.close()
Where el is some csv file.
Edit2:
It appears that while writing to a zipfile some data is lost.
Some suggestions:
(1) You call
testzipbut ignore the returned value. It may mess things up if the archive is empty (as it is in this case). Remove the call totestzip.(2) Test the integrity of the created file by another means e.g. (a)
linux_zipfile_executable -t your_created_archive.zip(b) short Python script usingtestzip. Try some other extraction means.(3) Ignore the
mode='wb'pushers; that is relevant only to files opened with built-inopen. As the zipfile docs say, the only permissible modes arer,w, anda. Else:RuntimeError: ZipFile() requires mode "r", "w", or "a". The zipfile code actually does use thebflag when it opens the archive file using built-inopen.(4) Check carefully that in the flurry of trying to find your problem you are in fact comparing the correct pair of csv files.
(5) Post the 3 files (input, output, and .zip) on the web somewhere.