mime

package
v0.0.0-...-d98ca20 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: GPL-3.0, Apache-2.0 Imports: 7 Imported by: 0

README

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

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

Directories

Path Synopsis
package freedesktop provides the verbatim FreeDesktop shared-mime-lib decoders.
package freedesktop provides the verbatim FreeDesktop shared-mime-lib decoders.
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
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

Jump to

Keyboard shortcuts

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