Popularity
4.1
Growing
Activity
7.9
Growing
129
3
13

Description

A package for detecting mime types and extensions based on magic numbers

Programming language: Go
Tags: Utilities     Golang     Magic Numbers     File Signature    
Latest version: v0.3.17

mimetype alternatives and similar packages

Based on the "Utilities" category

Do you think we are missing an alternative of mimetype or a related project?

Add another 'Utilities' Package

README

mimetype

A package for detecting MIME types and extensions based on magic numbers No bindings, all written in pure go

Install

go get github.com/gabriel-vasile/mimetype

Use

The library exposes three functions you can use in order to detect a file type. See Godoc for full reference.

func Detect(in []byte) (mime, extension string) {...}
func DetectReader(r io.Reader) (mime, extension string, err error) {...}
func DetectFile(file string) (mime, extension string, err error) {...}

When detecting from a ReadSeeker interface, such as os.File, make sure to reset the offset of the reader to the beginning if needed:

_, err = file.Seek(0, io.SeekStart)

Supported MIME types

See [supported mimes](supported_mimes.md) for the list of detected MIME types. If support is needed for a specific file format, please open an issue.

Structure

mimetype uses an hierarchical structure to keep the matching functions. This reduces the number of calls needed for detecting the file type. The reason behind this choice is that there are file formats used as containers for other file formats. For example, Microsoft office files are just zip archives, containing specific metadata files.

Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).


*Note that all licence references and agreements mentioned in the mimetype README section above are relevant to that project's source code only.