python - determining whether a MIME type is binary or text-based -
is there library allows determining whether given content type binary or text-based?
obviously text/*
textual, things application/json
, image/svg+xml
or application/x-latex
it's rather tricky without inspecting actual data.
there's wrapper libmagic python -- pymagic. thats easiest method accomplish want. keep in mind magic fingerprint. can have false-positives if 'looks' file format, cases pymagic give need.
one thing watch out 'simple solution' of checking see if of characters 'outside' printable ascii range, encounter unicode binary (and in fact, binary) though it's textual content.
Comments
Post a Comment