Mime is a relativly fast mime detection library using data from FreeDesktop's Shared mime info spec.

It is not a 100% implementation of the specification designed for webservers. It skips non-extension globs such as AUTHORS because most people dont want a file called AUTHORS to have the mime type text/x-authors

Expand ▾ Collapse ▴



package mime implements part of the shared-mime-info spec for guessing by extension and partial matching by header



This section is empty.


This section is empty.


This section is empty.


type Database

type Database struct {
	// contains filtered or unexported fields

Database holds the LUTs for glob matching and magic matching

func NewDatabase

func NewDatabase() *Database

NewDatabase Creates a new empty database

func (*Database) GuessExtByMIME

func (d *Database) GuessExtByMIME(mime string) string

GuessExtByMIME attempts to get a file extension (including the dot) by a mime type.

func (*Database) GuessMIMEByHeader

func (d *Database) GuessMIMEByHeader(header []byte) string

GuessMIMEByHeader attemtps to deterimine the MIME type by the file's header. It returns "" on failure

func (*Database) GuessMIMEByName

func (d *Database) GuessMIMEByName(name string) string

GuessMIMEByName guesses a mime type by filename. This is faster than guessing by magic, but very easy to fool returns a empty string on failure

func (*Database) ReadFreeDesktop

func (db *Database) ReadFreeDesktop(database io.Reader) error

ReadFreeDesktop reads into a existing database from a XML document stream describing mime matching

func (*Database) RecommendedLength

func (d *Database) RecommendedLength() int

RecommendedLength returns the length required by GuessMIMEByHeader for all matches


Path Synopsis
freedesktop package freedesktop provides the verbatim FreeDesktop shared-mime-lib decoders.
minimal package minimal provides a more minimal set of mime types tailored more to webservers where serving a video with the corrent MIME is more important than a word document