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",
"--mime-type",
"-"], env={"LANG": 'C'}, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as p:
p.stdin.write(data.encode() if isinstance(data, str) else data)
p.stdin.close()
try:
p.stdin.write(data.encode() if isinstance(data, str) else data)
p.stdin.close()
except BrokenPipeError:
pass
p.wait()
if p.returncode == 0:
return p.stdout.read().decode('utf-8', 'replace').strip()