Explore Elixir’s MIME immutable library in details

Explore Elixir’s MIME immutable library in details
Average rating: 0
(0 votes)

Here in Syndicode we see the great future for Elixir. That’s why we spend quite a lot of time investigating its features and tools. And today we are presenting Elixir’s MIME, a read-only and immutable library that embeds the MIME type database, so, users can map MIME (Multipurpose Internet Mail Extensions) types to extensions and vice-versa. 

One of the goals of this library is to offer a performant lookup of the MIME database at runtime, that’s why new MIME types can only be added at compile-time via configuration, but we’ll talk about this option later. First, let’s review its public API.

MIME offers a short set of functions, which cover the most relevant cases when you work with MIME types.

extensions(String.t()) ::

Returns the extensions associated with the given MIME type.

type(String.t()) :: String.t()

Returns the MIME type related to the given file extension.

from_path(Path.t()) :: String.t()

Guesses the MIME type based on the path’s extension.

has_type?(String.t()) :: boolean

Returns whether an extension has a MIME type associated.

valid?(String.t()) :: boolean

Returns whether a MIME type is registered.

At the time of this writing, and according to the statistics available from the Hex package manager, the MIME library has 21 dependents projects, among those projects you can find: Plug, Phoenix, Tesla, Swoosh, etc., and have been downloaded almost 6 million times. But more importantly, is how the MIME library is implemented, its code is really concise, it’s around 200 SLOC (Source Lines Of Code) including comments, and embed captivating concepts.

Elixir MIME is a short but powerful library, its goal is clear, and in just around 200 SLOC you can see a lot of nice concepts, like meta-programmingfile streamspattern matchingmacrosunquote fragmentsdynamic module creationdynamic recompilation at boot-time, among other really cool stuff.

You can explore different types of functions here. Thanks for reading and enjoy using new great tools and subscribe to our weekly newsletter to find more interesting information!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111