Detect MIME types and file extensions in Go from magic numbers
open sourceMITfree
mimetype is a Go package that detects a file's MIME type and extension from its magic numbers, from a byte slice, a reader or a file path. It supports a long list of formats, prioritises common ones, tells text from binary files and can be extended with new formats. It has no external dependencies or C bindings and is safe for concurrent use. It's by Gabriel Vasile.
Problems it solves
- detect the real file type of an upload in Go
- check an uploaded file's MIME type without trusting its extension
- tell text files from binary files in Go
Features
- MIME type and extension detection by magic numbers
- detect from bytes, readers or files
- text vs binary detection
- extensible with new formats
- no dependencies, no cgo, goroutine safe
