Open rustonaut opened 7 years ago
tree_magic
seems worth a try but:
the problem is tree_magic::from_u8
does never fail it fill always detect some mime,
e.g. text/plain
or application/octet-stream
but thats well suboptimal.
First a utf8 file can contain 0 bytes but sill be detected as octet-stream.
Second utf8 does not allow 0xFF as byte (and some other encoding do not either,
thats why it's used as magic number) but a file only consisting of 0xFF
is still
detected as text/plain
.
Instead of a brave apporach a cautious is needed. If there are magic numbers use them else bail.
There had been some discussion about how to best handle mime sniffing mainly:
The conclusion was that it might be best to make this configurable to some degree
there is currently a limited implementation in mail-codec-composition which
But this is very limited e.g. .tar.gz/.tgz is not even in conduit-media-types. Also it is currently only used for sniffing embedding media types in templates, so its enough there to be this way.
In future it might make sense to:
mail-codec
crate (or is called by it / as in not specific to composition templates)
the
mime_sniffer
crate is quite web specific and not what we need (it is content-type + data = mime, but we need data = mime or failure)