Get generic type of MIME (i.e. "image" from "image/png")
The MIME type have a Type (tautology) and a Subtype divided by /
. E.g. for MIME image/png
the image
is a type and png
is a subtype.
If we need to determine that the file is an image we can check the MIME type. There is no convenient method for this so everybody just doing string split by the /
sign.
All is clear for now but here comes a problem: for historical reasons most of archives and compressed files like *.gz
, *.tar
used just an application
. Take a look on the list:
"application/x-7z-compressed",
"application/x-7z-compressed-tar",
"application/x-ar",
"application/x-arj",
"application/x-bzip",
"application/x-bzip-compressed-tar",
"application/x-compress",
"application/x-compressed-tar",
"application/x-deb",
"application/x-gtar",
"application/x-gzip",
"application/x-lha",
"application/x-lhz",
"application/x-lzma",
"application/x-lzma-compressed-tar",
"application/x-rar",
"application/x-rar-compressed",
"application/x-tar",
"application/x-xz",
"application/x-xz-compressed-tar",
"application/x-zip",
"application/x-zip-compressed",
"application/zip",
"multipart/x-zip",
"application/x-rpm",
"application/x-jar",
"application/x-java-archive",
"application/x-lzop",
"application/x-zoo",
"application/x-cd-image",
"application/x-7z-compressed",
If we want to know that the given file is an archive we can't just use it's Type application
as we did with images.
In the same time the shared-mime-info declared an icon associated with each type and the icon is always "package-x-generic" for all archives (tar, zip, rar) and all compressed file (gz, xz, zst).
For a XFCE program I tried to use this icon as a clear indicator that the file is an archive. Please read comments and concerns https://bugzilla.xfce.org/show_bug.cgi?id=15917
So here is a proposition: can we introduce some method to get the kind of "generic type" or "type group"?
Then we can use it instead of the icon but also it can simplify things for those who parsing MIME by splitting it by /
?