Are you interested in a pull-request with something like this?
def mimetype_from_stream(stream, filename=None):
"""
Reads in stream, attempts to identify content based
off magic number and will return the mimetype.
If filename is provided it will be used in the computation.
"""
assert isinstance(stream, BytesIO)
head, foot = _stream_details(stream)
ext = puremagic.ext_from_filename(filename) if filename else None
return puremagic.main._magic(head, foot, True, ext)
def _stream_details(stream):
""" Grab the start and end of the stream"""
assert isinstance(stream, BytesIO)
max_head, max_foot = puremagic.main._max_lengths()
head = stream.read(max_head)
try:
stream.seek(-max_foot, os.SEEK_END)
except IOError:
stream.seek(0)
foot = stream.read()
return head, foot
I will mimic your from_string function more in the pull-request. In my case I only need the mime-type, not the extension.
Are you interested in a pull-request with something like this?
I will mimic your
from_string
function more in the pull-request. In my case I only need the mime-type, not the extension.