diff --git a/src/hanoi_util.erl b/src/hanoi_util.erl index ba8e4c0..c72ff50 100644 --- a/src/hanoi_util.erl +++ b/src/hanoi_util.erl @@ -62,7 +62,7 @@ encode_index_node(KVList, Compress) -> OutData = [?SNAPPY_COMPRESSION|Snappied] end; gzip -> - GZipData = zlib:gzip(TermData); + GZipData = zlib:gzip(TermData), if byte_size(GZipData) > byte_size(TermData) -> OutData = [?NO_COMPRESSION|TermData]; true -> diff --git a/src/hanoi_writer.erl b/src/hanoi_writer.erl index 50e6bea..a02bea2 100644 --- a/src/hanoi_writer.erl +++ b/src/hanoi_writer.erl @@ -190,9 +190,9 @@ close_node(#state{nodes=[#node{ level=Level, members=NodeMembers }|RestNodes], c {ok, BlockData} = hanoi_util:encode_index_node(OrderedMembers, Compress), NodePos = State#state.index_file_pos, - BlockSize = byte_size(BlockData), + BlockSize = erlang:iolist_size(BlockData), Data = [ <<(BlockSize+2):32/unsigned, Level:16/unsigned>> | BlockData ], - DataSize = BlockData + 6, + DataSize = BlockSize + 6, ok = file:write(State#state.index_file, Data),