diff options
author | John Christopher Anderson <jchris@apache.org> | 2010-01-29 22:43:33 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2010-01-29 22:43:33 +0000 |
commit | ee09a0de9f8356abe24a0ac0f26cdff35f8fa704 (patch) | |
tree | 1cf02264f5ee72216e5add7deda235c1504cf5ec /src/couchdb/couch_util.erl | |
parent | 5affb01e4ee059ad9b82000625f2bdc989019a16 (diff) |
Allow storing attachments in compressed form. Closes COUCHDB-583. Thanks Filipe Manana
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@904650 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r-- | src/couchdb/couch_util.erl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl index 45d1d336..ca36a6db 100644 --- a/src/couchdb/couch_util.erl +++ b/src/couchdb/couch_util.erl @@ -22,6 +22,7 @@ -export([to_binary/1, to_integer/1, to_list/1, url_encode/1]). -export([json_encode/1, json_decode/1]). -export([verify/2]). +-export([compressible_att_type/1]). -include("couch_db.hrl"). -include_lib("kernel/include/file.hrl"). @@ -440,3 +441,25 @@ verify(X, Y) when is_list(X) and is_list(Y) -> false end; verify(_X, _Y) -> false. + +compressible_att_type(MimeType) when is_binary(MimeType) -> + compressible_att_type(?b2l(MimeType)); +compressible_att_type(MimeType) -> + TypeExpList = re:split( + couch_config:get("attachments", "compressible_types", ""), + "\\s+", + [{return, list}] + ), + lists:any( + fun(TypeExp) -> + Regexp = "^\\s*" ++ + re:replace(TypeExp, "\\*", ".*", [{return, list}]) ++ "\\s*$", + case re:run(MimeType, Regexp, [caseless]) of + {match, _} -> + true; + _ -> + false + end + end, + [T || T <- TypeExpList, T /= []] + ). |