mimetypes

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const NO_MIME string = ""

Variables

View Source
var DefaultMimetypeMap = map[string]string{
	"html": "text/html",
	"htm":  "text/html",
	"txt":  "text/plain",
	"css":  "text/css",
	"csv":  "text/csv",
	"js":   "application/javascript",
	"json": "application/json",
	"xml":  "application/xml",
	"gif":  "image/gif",
	"jpeg": "image/jpeg",
	"jpg":  "image/jpeg",
	"png":  "image/png",
	"svg":  "image/svg+xml",
	"ico":  "image/x-icon",
	"webp": "image/webp",
	"mp4":  "video/mp4",
	"webm": "video/webm",
	"pdf":  "application/pdf",
	"zip":  "application/zip",
	"gz":   "application/gzip",
	"tar":  "application/x-tar",
	"7z":   "application/x-7z-compressed",
	"rar":  "application/x-rar-compressed",
	"bz2":  "application/x-bzip2",
	"mp3":  "audio/mpeg",
	"wav":  "audio/wav",
	"ogg":  "audio/ogg",
	"flac": "audio/flac",
	"mpg":  "video/mpeg",
	"mpeg": "video/mpeg",
	"mov":  "video/quicktime",
	"avi":  "video/x-msvideo",
	"wmv":  "video/x-ms-wmv",
}

Functions

func ContainsGuesser

func ContainsGuesser(mimeType string, contains [][]byte) func(filename string, data []byte) string

ContainsGuesser returns a guesser function that will check if the data contains any of the given byte slices

If it does, it will return the given mimetype

func ExtensionGuesser added in v1.0.1

func ExtensionGuesser(m map[string]string) func(filename string, data []byte) string

ExtensionGuesser returns a guesser function that will check if the filename ends with the given extension. If it does, it will return the given mimetype.

This function takes a map of extensions to mimetypes

func Guess

func Guess(filename string, data []byte) string

Guess returns the mime type of the given data

Otherwise return "application/octet-stream"

func LocalDatabaseGuesser

func LocalDatabaseGuesser(filename string, data []byte) string

Check for signatures of known mimetypes in the data

func PlaintextGuesser

func PlaintextGuesser(filename string, data []byte) string

PlaintextGuesser returns a guesser function that will check if the data is ascii or unicode

If it is ascii, it will return "text/plain; charset=utf-8"

If it is unicode, it will return "text/plain; charset=utf-16"

func With

func With(guesser ...GuesserFunc)

With registers a new guesser function

Types

type Guesser

type Guesser struct {
	Funcs []GuesserFunc
}

func New

func New() *Guesser

func (*Guesser) Guess

func (g *Guesser) Guess(filename string, data []byte) string

Guess returns the mime type of the given data

Otherwise return "application/octet-stream"

func (*Guesser) With

func (g *Guesser) With(guesser ...GuesserFunc)

type GuesserFunc

type GuesserFunc func(filename string, data []byte) string

Jump to

Keyboard shortcuts

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