summaryrefslogtreecommitdiff
path: root/src/couch/src/couch_compress.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/couch/src/couch_compress.erl')
-rw-r--r--src/couch/src/couch_compress.erl28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/couch/src/couch_compress.erl b/src/couch/src/couch_compress.erl
index cfcc2a481..59d692058 100644
--- a/src/couch/src/couch_compress.erl
+++ b/src/couch/src/couch_compress.erl
@@ -25,21 +25,19 @@
-define(TERM_PREFIX, 131).
-define(COMPRESSED_TERM_PREFIX, 131, 80).
-
get_compression_method() ->
case config:get("couchdb", "file_compression") of
- undefined ->
- ?DEFAULT_COMPRESSION;
- Method1 ->
- case string:tokens(Method1, "_") of
- [Method] ->
- list_to_existing_atom(Method);
- [Method, Level] ->
- {list_to_existing_atom(Method), list_to_integer(Level)}
- end
+ undefined ->
+ ?DEFAULT_COMPRESSION;
+ Method1 ->
+ case string:tokens(Method1, "_") of
+ [Method] ->
+ list_to_existing_atom(Method);
+ [Method, Level] ->
+ {list_to_existing_atom(Method), list_to_integer(Level)}
+ end
end.
-
compress(<<?SNAPPY_PREFIX, _/binary>> = Bin, snappy) ->
Bin;
compress(<<?SNAPPY_PREFIX, _/binary>> = Bin, Method) ->
@@ -57,11 +55,11 @@ compress(Term, snappy) ->
try
{ok, CompressedBin} = snappy:compress(Bin),
<<?SNAPPY_PREFIX, CompressedBin/binary>>
- catch exit:snappy_nif_not_loaded ->
- Bin
+ catch
+ exit:snappy_nif_not_loaded ->
+ Bin
end.
-
decompress(<<?SNAPPY_PREFIX, Rest/binary>>) ->
{ok, TermBin} = snappy:decompress(Rest),
binary_to_term(TermBin);
@@ -70,7 +68,6 @@ decompress(<<?TERM_PREFIX, _/binary>> = Bin) ->
decompress(_) ->
error(invalid_compression).
-
is_compressed(<<?SNAPPY_PREFIX, _/binary>>, Method) ->
Method =:= snappy;
is_compressed(<<?COMPRESSED_TERM_PREFIX, _/binary>>, {deflate, _Level}) ->
@@ -84,7 +81,6 @@ is_compressed(Term, _Method) when not is_binary(Term) ->
is_compressed(_, _) ->
error(invalid_compression).
-
uncompressed_size(<<?SNAPPY_PREFIX, Rest/binary>>) ->
{ok, Size} = snappy:uncompressed_length(Rest),
Size;