Skip to content
Browse files

Enable lz4 compression

  • Loading branch information...
1 parent 923dbe3 commit 35de7a33009ff0f6e305e359305709cb2af7fca2 @krestenkrab krestenkrab committed
Showing with 13 additions and 13 deletions.
  1. +1 −1 rebar.config
  2. +1 −1 src/hanoidb.erl
  3. +11 −11 src/hanoidb_util.erl
View
2 rebar.config
@@ -30,7 +30,7 @@
, {plain_fsm, "1.1.*", {git, "git://github.com/gburd/plain_fsm", {branch, "master"}}}
, {basho_bench, ".*", {git, "git://github.com/basho/basho_bench", {branch, "master"}}}
, {triq, ".*", {git, "git://github.com/krestenkrab/triq", {branch, "master"}}}
-% , {lz4, ".*", {git, "git://github.com/gburd/erlang-lz4.git", {branch, "master"}}}
+ , {lz4, ".*", {git, "git://github.com/krestenkrab/erlang-lz4.git", {branch, "master"}}}
% , {edown, "0.3.*", {git, "git://github.com/esl/edown.git", {branch, "master"}}}
% , {asciiedoc, "0.1.*", {git, "git://github.com/norton/asciiedoc.git", {branch, "master"}}}
% , {triq, ".*", {git, "git://github.com/krestenkrab/triq.git", {branch, "master"}}}
View
2 src/hanoidb.erl
@@ -62,7 +62,7 @@
-type hanoidb() :: pid().
-type key_range() :: #key_range{}.
--type config_option() :: {compress, none | gzip | snappy} %lz4
+-type config_option() :: {compress, none | gzip | snappy | lz4}
| {page_size, pos_integer()}
| {read_buffer_size, pos_integer()}
| {write_buffer_size, pos_integer()}
View
22 src/hanoidb_util.erl
@@ -89,7 +89,7 @@ estimate_node_size_increment(_KVList, Key, Value)
-define(NO_COMPRESSION, 0).
-define(SNAPPY_COMPRESSION, 1).
-define(GZIP_COMPRESSION, 2).
-%%-define(LZ4_COMPRESSION, 3).
+-define(LZ4_COMPRESSION, 3).
use_compressed(UncompressedSize, CompressedSize) when CompressedSize < UncompressedSize ->
true;
@@ -104,14 +104,14 @@ compress(snappy, Bin) ->
false ->
{?NO_COMPRESSION, Bin}
end;
-%% compress(lz4, Bin) ->
-%% {ok, CompressedBin} = lz4:compress(Bin),
-%% case use_compressed(erlang:iolist_size(Bin), erlang:iolist_size(CompressedBin)) of
-%% true ->
-%% {?LZ4_COMPRESSION, CompressedBin};
-%% false ->
-%% {?NO_COMPRESSION, Bin}
-%% end;
+compress(lz4, Bin) ->
+ {ok, CompressedBin} = lz4:compress(erlang:iolist_to_binary(Bin)),
+ case use_compressed(erlang:iolist_size(Bin), erlang:iolist_size(CompressedBin)) of
+ true ->
+ {?LZ4_COMPRESSION, CompressedBin};
+ false ->
+ {?NO_COMPRESSION, Bin}
+ end;
compress(gzip, Bin) ->
CompressedBin = zlib:gzip(Bin),
case use_compressed(erlang:iolist_size(Bin), erlang:iolist_size(CompressedBin)) of
@@ -128,8 +128,8 @@ uncompress(<<?NO_COMPRESSION, Data/binary>>) ->
uncompress(<<?SNAPPY_COMPRESSION, Data/binary>>) ->
{ok, UncompressedData} = snappy:decompress(Data),
UncompressedData;
-%%uncompress(<<?LZ4_COMPRESSION, Data/binary>>) ->
-%% lz4:uncompress(Data);
+uncompress(<<?LZ4_COMPRESSION, Data/binary>>) ->
+ lz4:uncompress(Data);
uncompress(<<?GZIP_COMPRESSION, Data/binary>>) ->
zlib:gunzip(Data).

0 comments on commit 35de7a3

Please sign in to comment.
Something went wrong with that request. Please try again.