项目作者: erlangpack

项目描述 :
Erlang MIME types library
高级语言: Erlang
项目地址: git://github.com/erlangpack/mimetypes.git
创建时间: 2011-08-04T02:42:15Z
项目社区:https://github.com/erlangpack/mimetypes

开源协议:Other

下载


Build Status
Hex.pm version
Hex.pm Downloads
Hex.pm Documentation
Erlang Versions

mimetypes

mimetypes is an Erlang library to fetch MIME extension/name mappings.

Usage

  1. 1> application:start(mimetypes).
  2. ok
  3. 2> mimetypes:extension(<<"js">>).
  4. <<"application/javascript">>
  5. 3> mimetypes:extension(<<"mb">>).
  6. <<"application/mathematica">>
  7. 4> mimetypes:extension(<<"html">>).
  8. <<"text/html">>
  9. 5> mimetypes:extension(<<"m3u8">>).
  10. [<<"application/vnd.apple.mpegurl">>,
  11. <<"application/x-mpegurl">>]
  12. 6> mimetypes:filename("/a/b.js").
  13. <<"application/javascript">>
  14. 7> mimetypes:extensions(<<"application/mathematica">>).
  15. [<<"ma">>,<<"nb">>,<<"mb">>]

Additional types

Additional mappings can be loaded at runtime using the mimetypes:load/2
function. If this function is timing out it is possible to increase the
timeout using mimetypes:load/3.

  1. 1> application:start(mimetypes).
  2. ok
  3. 2> mimetypes:load(default, [{<<"ext">>, <<"new/type">>}]).
  4. ok
  5. 3> mimetypes:extension(<<"ext">>).
  6. [<<"application/vnd.novadigm.ext">>,<<"new/type">>]
  7. 2> mimetypes:load(default, [{<<"ext">>, <<"new/type">>}], 10000).
  8. ok

Additional mappings can also be specified using the application environment
variables for the mimetypes application. These can be added to the
config file specified using the erl -config flag.

  1. [{mimetypes, [
  2. %% Wait for all additional types to be loaded before returning from
  3. %% application:start(mimetypes). Set to false to return immidiately
  4. %% and load them in the background.
  5. {load_async, true},
  6. %% Timeout to use for calls to mimetypes:load/3 while loading additional
  7. %% mimetypes. The default is the same as for mimetypes:load/2. You may
  8. %% need to increase this value.
  9. {load_timeout, 5000},
  10. {load, [
  11. {default, [
  12. {<<"ext">>, <<"new/type">>}
  13. ]}
  14. ]}
  15. ]}].