Fix a problem when dealing with huge files: file cmd responds before all the content has been writed
This commit is contained in:
parent
e68cdc1108
commit
f2cac09f6f
@ -62,8 +62,11 @@ def _guess_mime(data):
|
||||
"--brief",
|
||||
"--mime-type",
|
||||
"-"], 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.close()
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
p.wait()
|
||||
if p.returncode == 0:
|
||||
return p.stdout.read().decode('utf-8', 'replace').strip()
|
||||
|
Reference in New Issue
Block a user