magic

package
v0.0.0-...-379680d Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package magic implements MIME type sniffing of data based on the well-known "magic" number prefixes in the file.

Index

Constants

This section is empty.

Variables

View Source
var VideoExtensions = map[string]bool{
	"m1v": true,
	"m2v": true,
	"m4v": true,
	"mkv": true,
}

VideoExtensions are common video filename extensions that are not covered by mime.TypeByExtension.

Functions

func HasExtension

func HasExtension(filename string, extensions map[string]bool) bool

HasExtension returns whether the file extension of filename is among extensions. It is a case-insensitive lookup, optimized for the ASCII case.

func MIMEType

func MIMEType(hdr []byte) string

MIMEType returns the MIME type from the data in the provided header of the data. It returns the empty string if the MIME type can't be determined.

func MIMETypeByExtension

func MIMETypeByExtension(ext string) string

MIMETypeByExtension calls mime.TypeByExtension, and removes optional parameters, to keep only the type and subtype.

func MIMETypeFromReader

func MIMETypeFromReader(r io.Reader) (mime string, reader io.Reader)

MIMETypeFromReader takes a reader, sniffs the beginning of it, and returns the mime (if sniffed, else "") and a new reader that's the concatenation of the bytes sniffed and the remaining reader.

func MIMETypeFromReaderAt

func MIMETypeFromReaderAt(ra io.ReaderAt) (mime string)

MIMETypeFromReaderAt takes a ReaderAt, sniffs the beginning of it, and returns the MIME type if sniffed, else the empty string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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