summaryrefslogtreecommitdiff
path: root/src/journal/compress.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-24 21:24:09 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-26 01:41:04 -0400
commit76cc0bf682b944d4cb611f1b37c71fce140f8fe7 (patch)
treeed4634c5efc5d178d2c751072ed29add5f1de5a1 /src/journal/compress.c
parent8c9778383b2cf64c45323bb10b741aa3beae28ca (diff)
journal/compress: simplify compress_blob
Diffstat (limited to 'src/journal/compress.c')
-rw-r--r--src/journal/compress.c28
1 files changed, 7 insertions, 21 deletions
diff --git a/src/journal/compress.c b/src/journal/compress.c
index a4427be75a..cafe8f4f54 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -28,9 +28,8 @@
#include "compress.h"
bool compress_blob(const void *src, uint64_t src_size, void *dst, uint64_t *dst_size) {
- lzma_stream s = LZMA_STREAM_INIT;
lzma_ret ret;
- bool b = false;
+ size_t out_pos = 0;
assert(src);
assert(src_size > 0);
@@ -40,30 +39,17 @@ bool compress_blob(const void *src, uint64_t src_size, void *dst, uint64_t *dst_
/* Returns false if we couldn't compress the data or the
* compressed result is longer than the original */
- ret = lzma_easy_encoder(&s, LZMA_PRESET_DEFAULT, LZMA_CHECK_NONE);
+ ret = lzma_easy_buffer_encode(LZMA_PRESET_DEFAULT, LZMA_CHECK_NONE, NULL,
+ src, src_size, dst, &out_pos, *dst_size);
if (ret != LZMA_OK)
return false;
- s.next_in = src;
- s.avail_in = src_size;
- s.next_out = dst;
- s.avail_out = src_size;
-
- /* Does it fit? */
- if (lzma_code(&s, LZMA_FINISH) != LZMA_STREAM_END)
- goto fail;
-
/* Is it actually shorter? */
- if (s.avail_out == 0)
- goto fail;
-
- *dst_size = src_size - s.avail_out;
- b = true;
-
-fail:
- lzma_end(&s);
+ if (out_pos == *dst_size)
+ return false;
- return b;
+ *dst_size = out_pos;
+ return true;
}
bool uncompress_blob(const void *src, uint64_t src_size,