Fix a problem when dealing with huge files: file cmd responds before all the content has been writed

This commit is contained in:
nemunaire 2018-10-23 23:45:12 +02:00
parent e68cdc1108
commit f2cac09f6f

View File

@ -62,8 +62,11 @@ def _guess_mime(data):
"--brief", "--brief",
"--mime-type", "--mime-type",
"-"], env={"LANG": 'C'}, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as p: "-"], env={"LANG": 'C'}, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as p:
try:
p.stdin.write(data.encode() if isinstance(data, str) else data) p.stdin.write(data.encode() if isinstance(data, str) else data)
p.stdin.close() p.stdin.close()
except BrokenPipeError:
pass
p.wait() p.wait()
if p.returncode == 0: if p.returncode == 0:
return p.stdout.read().decode('utf-8', 'replace').strip() return p.stdout.read().decode('utf-8', 'replace').strip()