MimeType
MimeType is a library that sacrifices a few MB of memory for the sake of being super fast at getting your MimeType information. We would rather use 1MB of memory, and get twice (if not more) the speed, than rely on other methods of caching which don't perform nearly as fast.
Installation
gem "mimetype"
Usage
require "mimetype"
MimeType.lookup_by_extension(".jpg")
MimeType.lookup_by_content_type("text/plain")
MimeType.lookup_by_filename(Pathutil.new("hello.txt"))
MimeType.lookup_by_filename(File.new("hello.txt"))
MimeType.lookup_by_filename("hello.txt")
Performance
MimeType: 19983 obj @ 1495392 bytes w/ 5467 obj @ 372766 bytes retained
MIME::Type: 96527 obj @ 7607027 bytes w/ 30706 obj @ 2717341 bytes retained
MiniMime: 399 obj @ 41769 bytes w/ 54 obj @ 7229 bytes retained
Warming up --------------------------------------
MIME::TYPE by ext 27.428k i/100ms
MimeType by ext 139.974k i/100ms
MiniMime by ext 50.359k i/100ms
Calculating -------------------------------------
MIME::TYPE by ext 299.961k (