zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

cow_mimetypes.erl.src (2608B)


      1 %% Copyright (c) 2013-2018, Loïc Hoguin <essen@ninenines.eu>
      2 %%
      3 %% Permission to use, copy, modify, and/or distribute this software for any
      4 %% purpose with or without fee is hereby granted, provided that the above
      5 %% copyright notice and this permission notice appear in all copies.
      6 %%
      7 %% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      8 %% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      9 %% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     10 %% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     11 %% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     12 %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     13 %% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     14 
     15 -module(cow_mimetypes).
     16 
     17 -export([all/1]).
     18 -export([web/1]).
     19 
     20 %% @doc Return the mimetype for any file by looking at its extension.
     21 
     22 -spec all(binary()) -> {binary(), binary(), []}.
     23 all(Path) ->
     24 	case filename:extension(Path) of
     25 		<<>> -> {<<"application">>, <<"octet-stream">>, []};
     26 		%% @todo Convert to string:lowercase on OTP-20+.
     27 		<< $., Ext/binary >> -> all_ext(list_to_binary(string:to_lower(binary_to_list(Ext))))
     28 	end.
     29 
     30 %% @doc Return the mimetype for a Web related file by looking at its extension.
     31 
     32 -spec web(binary()) -> {binary(), binary(), []}.
     33 web(Path) ->
     34 	case filename:extension(Path) of
     35 		<<>> -> {<<"application">>, <<"octet-stream">>, []};
     36 		%% @todo Convert to string:lowercase on OTP-20+.
     37 		<< $., Ext/binary >> -> web_ext(list_to_binary(string:to_lower(binary_to_list(Ext))))
     38 	end.
     39 
     40 %% Internal.
     41 
     42 %% GENERATED
     43 all_ext(_) -> {<<"application">>, <<"octet-stream">>, []}.
     44 
     45 web_ext(<<"css">>) -> {<<"text">>, <<"css">>, []};
     46 web_ext(<<"gif">>) -> {<<"image">>, <<"gif">>, []};
     47 web_ext(<<"html">>) -> {<<"text">>, <<"html">>, []};
     48 web_ext(<<"htm">>) -> {<<"text">>, <<"html">>, []};
     49 web_ext(<<"ico">>) -> {<<"image">>, <<"x-icon">>, []};
     50 web_ext(<<"jpeg">>) -> {<<"image">>, <<"jpeg">>, []};
     51 web_ext(<<"jpg">>) -> {<<"image">>, <<"jpeg">>, []};
     52 web_ext(<<"js">>) -> {<<"application">>, <<"javascript">>, []};
     53 web_ext(<<"mp3">>) -> {<<"audio">>, <<"mpeg">>, []};
     54 web_ext(<<"mp4">>) -> {<<"video">>, <<"mp4">>, []};
     55 web_ext(<<"ogg">>) -> {<<"audio">>, <<"ogg">>, []};
     56 web_ext(<<"ogv">>) -> {<<"video">>, <<"ogg">>, []};
     57 web_ext(<<"png">>) -> {<<"image">>, <<"png">>, []};
     58 web_ext(<<"svg">>) -> {<<"image">>, <<"svg+xml">>, []};
     59 web_ext(<<"wav">>) -> {<<"audio">>, <<"x-wav">>, []};
     60 web_ext(<<"webm">>) -> {<<"video">>, <<"webm">>, []};
     61 web_ext(_) -> {<<"application">>, <<"octet-stream">>, []}.