Library for cross-platform mapping of MIME types to file extensions and vice versa [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this questionTL;DR: The question is:
- Do you know of a cross-platform library that I can use from C++ to map MIME type(s) <-> file extension(s)?
My application is supposed to handle image and video files alike. I try to be as platform agnostic as possible, so I chose to use Qt4 as my main library. The Phonon framework (for handling video files) and QImage (for handling images, obviously) can both report which file formats they support. Phonon will return a list of MIME types that is supported by the installed backend and QImage expresses the supported file formats with a list of file extensions.
The application should find out from a QString fileName
whether to create a VideoObject
or an ImageObject
from it. My approach is to create a map<QString, FuncPtr>
that returns the appropriate factory method for creating the correct object. For the string I currently use the file extension, because it is very easy to infer the file extension from the file name. But now I do not have an elegant way to register the supported video file types, since I only know their MIME type.
If I used the MIME types for the key in my map<QString, FuncPtr>
, I would be faced with the problem how to
- a) map the file name to a MIME type (no clue how to do that platform independently and extensibly)
- b) map the file extensions provided by QImage to MIME types
I know that, according to my research up to now, many people suggest to use the "Apache mime.types file", which will preclude me from supporting new file formats (WebM, WebP, ...) when the client updates the back ends.
Other suggestions that I have found is to scan "/etc/mime.types" on Linux (I could do that) or to "query the registry" on Windows (no clue how to do that). But this seems very limited to those two platforms, what about Ma开发者_开发百科c OS X, etc.
In addition to the above stated question I also welcome other suggestions in any shape or form. Perhaps I am missing something brain dead obvious.
Like you already wrote on your question, I'd go for a mimefile from Apache or some Linux distribution and ship it with your application.
Personally I think there is no point in having a "library" for that to "stay permanently up-to-date".
MIME grew huge over the past years, but in reality you just need 1% or less of all defined MIME types in there. People don't have all sorts of file formats on their
If you want to browse some, IANA lists most of the popular MIME types.
TL;DR: Ship your application with a mostly complete mimefile from Apache or some Linux distribution and don't worry about reading it "live" from all target systems.
精彩评论