aboutsummaryrefslogtreecommitdiffstats
path: root/src/cow_mimetypes.erl.src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-10-31 10:33:21 +0100
committerLoïc Hoguin <[email protected]>2013-10-31 10:33:21 +0100
commit1797b412baa694e489b18732408e146f7c09f59d (patch)
tree928d49d3dfadac2b257f2a5218625f08d076a03f /src/cow_mimetypes.erl.src
parent85b695c177da63f8b2651c88f8bc43ee511c4509 (diff)
downloadcowlib-1797b412baa694e489b18732408e146f7c09f59d.tar.gz
cowlib-1797b412baa694e489b18732408e146f7c09f59d.tar.bz2
cowlib-1797b412baa694e489b18732408e146f7c09f59d.zip
Add the cow_mimetypes module for identifying mimetypes from ext
The module is partly generated from the big Apache mimetypes file.
Diffstat (limited to 'src/cow_mimetypes.erl.src')
-rw-r--r--src/cow_mimetypes.erl.src59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/cow_mimetypes.erl.src b/src/cow_mimetypes.erl.src
new file mode 100644
index 0000000..c387726
--- /dev/null
+++ b/src/cow_mimetypes.erl.src
@@ -0,0 +1,59 @@
+%% Copyright (c) 2013, Loïc Hoguin <[email protected]>
+%%
+%% Permission to use, copy, modify, and/or distribute this software for any
+%% purpose with or without fee is hereby granted, provided that the above
+%% copyright notice and this permission notice appear in all copies.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+-module(cow_mimetypes).
+
+-export([all/1]).
+-export([web/1]).
+
+%% @doc Return the mimetype for any file by looking at its extension.
+
+-spec all(file:filename_all()) -> binary() | false.
+all(Path) ->
+ case filename:extension(Path) of
+ <<>> -> false;
+ << $., Ext/binary >> -> all_ext(Ext)
+ end.
+
+%% @doc Return the mimetype for a Web related file by looking at its extension.
+
+-spec web(file:filename_all()) -> binary() | false.
+web(Path) ->
+ case filename:extension(Path) of
+ <<>> -> false;
+ << $., Ext/binary >> -> web_ext(Ext)
+ end.
+
+%% Internal.
+
+%% GENERATED
+all_ext(_) -> false.
+
+web_ext(<<"css">>) -> <<"text/css">>;
+web_ext(<<"gif">>) -> <<"image/gif">>;
+web_ext(<<"html">>) -> <<"text/html">>;
+web_ext(<<"htm">>) -> <<"text/html">>;
+web_ext(<<"ico">>) -> <<"image/x-icon">>;
+web_ext(<<"jpeg">>) -> <<"image/jpeg">>;
+web_ext(<<"jpg">>) -> <<"image/jpeg">>;
+web_ext(<<"js">>) -> <<"application/javascript">>;
+web_ext(<<"mp3">>) -> <<"audio/mpeg">>;
+web_ext(<<"mp4">>) -> <<"video/mp4">>;
+web_ext(<<"ogg">>) -> <<"audio/ogg">>;
+web_ext(<<"ogv">>) -> <<"video/ogg">>;
+web_ext(<<"png">>) -> <<"image/png">>;
+web_ext(<<"svg">>) -> <<"image/svg+xml">>;
+web_ext(<<"wav">>) -> <<"audio/x-wav">>;
+web_ext(<<"webm">>) -> <<"video/webm">>;
+web_ext(_) -> false.