Browse Source

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

master
nemunaire 4 years ago
parent
commit
f2cac09f6f
  1. 7
      archive.py

7
archive.py

@ -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()

Loading…
Cancel
Save