mime

package
v0.3.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Unknown = "application/octet-stream"

Unknown is what a name no glob claims guesses as.

Variables

This section is empty.

Functions

func DataDirs

func DataDirs() []string

DataDirs is the XDG data directory search order.

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

func Load(dirs []string) *Database

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) FileIcon added in v0.2.0

func (db *Database) FileIcon(mimeType string) string

FileIcon names the Lucide glyph for a file of mimeType: the glyph of its generic icon, the plain file for a generic icon without one.

func (*Database) IsA

func (db *Database) IsA(mimeType, base string) bool

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

func (db *Database) TypeByName(path string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL