• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

priv/H14-Jul-2017-1,4861,485

src/H03-May-2022-944499

test/H14-Jul-2017-13892

.travis.ymlH A D14-Jul-2017480 2220

LICENSEH A D14-Jul-20171.4 KiB2620

README.mdH A D14-Jul-20172.2 KiB7362

THANKSH A D14-Jul-2017174 21

package.exsH A D14-Jul-2017592 87

package.head.exsH A D14-Jul-2017580 87

rebar.configH A D03-May-202295 87

README.md

1mimetypes
2=========
3
4[![Build Status](https://travis-ci.org/erlangpack/mimetypes.svg?branch=master)](https://travis-ci.org/erlangpack/mimetypes)
5[![Hex pm](http://img.shields.io/hexpm/v/mimetypes.svg?style=flat)](https://hex.pm/packages/mimetypes)
6
7`mimetypes` is an Erlang library to fetch MIME extension/name mappings.
8
9Usage
10-----
11
12``` erlang
13$ erl -pa ebin
14Erlang R14B03 (erts-5.8.4) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [hipe] [kernel-poll:false]
15
16Eshell V5.8.4  (abort with ^G)
171> application:start(mimetypes).
18ok
192> mimetypes:extension(<<"js">>).
20<<"application/javascript">>
213> mimetypes:extension(<<"mb">>).
22<<"application/mathematica">>
234> mimetypes:extension(<<"html">>).
24<<"text/html">>
255> mimetypes:extension(<<"m3u8">>).
26[<<"application/vnd.apple.mpegurl">>,
27 <<"application/x-mpegurl">>]
286> mimetypes:filename("/a/b.js").
29<<"application/javascript">>
307> mimetypes:extensions(<<"application/mathematica">>).
31[<<"ma">>,<<"nb">>,<<"mb">>]
32```
33
34Additional types
35----------------
36
37Additional mappings can be loaded at runtime using the ```mimetypes:load/2```
38function. If this function is timing out it is possible to increase the
39timeout using ```mimetypes:load/3```.
40
41``` erlang
421> application:start(mimetypes).
43ok
442> mimetypes:load(default, [{<<"ext">>, <<"new/type">>}]).
45ok
463> mimetypes:extension(<<"ext">>).
47[<<"application/vnd.novadigm.ext">>,<<"new/type">>]
482> mimetypes:load(default, [{<<"ext">>, <<"new/type">>}], 10000).
49ok
50```
51
52Additional mappings can also be specified using the application environment
53variables for the ```mimetypes``` application. These can be added to the
54config file specified using the ```erl -config``` flag.
55
56``` erlang
57[{mimetypes, [
58    %% Wait for all additional types to be loaded before returning from
59    %% application:start(mimetypes). Set to false to return immidiately
60    %% and load them in the background.
61    {load_async, true},
62    %% Timeout to use for calls to mimetypes:load/3 while loading additional
63    %% mimetypes. The default is the same as for mimetypes:load/2. You may
64    %% need to increase this value.
65    {load_timeout, 5000},
66    {load, [
67        {default, [
68            {<<"ext">>, <<"new/type">>}
69        ]}
70    ]}
71]}].
72```
73