Documentation
¶
Overview ¶
Package mime guesses a file's mimetype from its name through the system's shared-mime-info database, and names the generic icon for it: what gio's g_content_type_guess (with no data) and g_content_type_get_generic_icon_name answer, in pure Go.
Index ¶
Constants ¶
const Unknown = "application/octet-stream"
Unknown is what a name no glob claims guesses as.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is a loaded shared-mime-info glob table plus the generic icon map.
func Load ¶
Load reads mime/globs2, generic-icons, aliases and subclasses from each data dir; an earlier directory's entry for the same pattern wins.
func System ¶
func System() *Database
System loads the database from the XDG data directories once: $XDG_DATA_HOME (or ~/.local/share) first, then $XDG_DATA_DIRS (or /usr/local/share:/usr/share). A missing database guesses Unknown for everything.
func (*Database) GenericIcon ¶
GenericIcon names the generic icon for a mimetype: the database's generic-icons entry, else `<media>-x-generic` (image-x-generic, text-x-generic), which is gio's rule.
func (*Database) IsA ¶
IsA reports whether mimeType is base or a subtype of it, with aliases resolved: g_content_type_is_a, shared-mime-info's is_subclass. Beyond the subclasses file every text/* is a text/plain and every non-inode type an application/octet-stream.
func (*Database) TypeByName ¶
TypeByName guesses the mimetype of a file from its base name: a literal name first, then the heaviest matching glob (the longest on a tie), else Unknown.