Xiaolong Liu <liuxiaolong...@126.com> added the comment:

Serhiy: Thanks for your explanation. 

The file was created by zipfile module. I used the script hundreds of times, 
while only once (the uploaded zipped file) was abnormal. 

Since the project ended a long time ago, I cannot reproduce the error right 
now. I will post the related code snippet I used.

import zipfile
import pathlib

def fileIsValid(filename):
filename = pathlib.Path(filename)
return True if filename.is_file() and filename.stat().st_size > 0 else False

def compress2zip(sourceFile,zipFile,destinationFile):
if not fileIsValid(zipFile):
pathlib.Path(zipFile).parent.mkdir(parents=True, exist_ok=True)
with zipfile.ZipFile(zipFile,'w',compression=zipfile.ZIP_DEFLATED) as myzip:
myzip.write(sourceFile,destinationFile)
dest_size = myzip.getinfo(destinationFile).file_size
else:
with zipfile.ZipFile(zipFile,'a',compression=zipfile.ZIP_DEFLATED) as myzip:
if not destinationFile in myzip.namelist():
myzip.write(sourceFile,destinationFile)
dest_size = myzip.getinfo(destinationFile).file_size
source_size = pathlib.Path(sourceFile).stat().st_size
if source_size == dest_size:
print('Succeeded -- compress -- %s' % str(destinationFile))
return True
else:
print('Failed -- compress -- %s' %str(destinationFile))
return False

files = list(pathlib.Path('000-original').glob('*.geojson'))
zipFile = pathlib.Path('0000.zip')
for file in files:
comp_re = compress2zip(file, zipFile, file.name)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41102>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to