ppai-plivo / go-mime-lib-compare

Comparison of Go MIME type detection libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-mime-lib-compare

A simple project to compare different Go projects/packages that detect MIME types.

Libraries

Library Implementation Stars Contributors
http.DetectContentType Pure Go
gabriel-vasile/mimetype Pure Go stars contrib
zRedShift/mimemagic Pure Go stars contrib
h2non/filetype Pure Go stars contrib
vimeo/go-magic/magic libmagic stars contrib
rakyll/magicmime libmagic stars contrib

Building

Dependency:

Some go packages for MIME type detection are libmagic wrappers.

$ brew install libmagic

Build:

$ go build

Use:

$ ./go-mime-lib-compare > out.md

See comparison results.

Summary

  • gabriel-vasile/mimetype is written in pure Go and has good detection capablities and uses a hierarchical detection structure.
  • Go wrappers of libmagic have the most accurate MIME type detection. However it entails use of cgo. Further, libmagic is not threadsafe and hence Go wrappers will have to use either sync.Mutex or runtime.LockOSThread.
  • Although h2non/filetype is written in pure Go, it doesn't detect a variety of types. Further, surprisingly, its detection is not deterministic. IOW, for the same input file, MIME type detected can be different on each run! This is not recommended for any production use.

About

Comparison of Go MIME type detection libraries

License:MIT License


Languages

Language:Go 100.0%