You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
I have been using magic library for detecting mime types and found that getting two different results for the same file when using
from_buffer
and
from_file
. Below is the python snippet I tried.
import magic
magic.Magic(mime=True, mime_encoding=True).from_buffer(open("Downloads/Document-magic.docx","r").read(1024))
'application/zip; charset=binary'
magic.Magic(mime=True, mime_encoding=True).from_file("Downloads/Document-magic.docx")
'application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=binary'
Python version 2.7.12
Does magic library support detecting mime types for files created on one drive or google docs.
Thanks in advance
Ya Right
@v00d00
I read 2kb instead of 1kb and got the same output as seen in from_file.
Any idea on a generic number of bytes to read so that it does not fail for any type of files.
Thanks.
Some files have their "signature" bytes at the end of the file, so the most reliable way would be the entire file, at least in my experience.
But as that may be impractical, more the more bytes the better.