From a55250cf1697671d536c8e0e5b846fa9d79c894d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 16 Mar 2012 14:14:22 +1100 Subject: [PATCH] Use libzpaq backend for decompression. --- libzpaq/libzpaq.h | 7 +++++++ lrzip.h | 1 + stream.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/libzpaq/libzpaq.h b/libzpaq/libzpaq.h index e09a616..25a070d 100644 --- a/libzpaq/libzpaq.h +++ b/libzpaq/libzpaq.h @@ -469,4 +469,11 @@ extern "C" void zpaq_compress(uchar *c_buf, long long *c_len, uchar *s_buf, long compress (&bufR, &bufW, level); } +extern "C" void zpaq_decompress(uchar *s_buf, long long *d_len, uchar *c_buf, long long c_len) { + bufRead bufR(c_buf, &c_len); + bufWrite bufW(s_buf, d_len); + + decompress(&bufR, &bufW); +} + #endif // LIBZPAQ_H diff --git a/lrzip.h b/lrzip.h index d4bf99f..297e227 100644 --- a/lrzip.h +++ b/lrzip.h @@ -43,4 +43,5 @@ bool clear_tmpinfile(rzip_control *control); void close_tmpinbuf(rzip_control *control); bool initialize_control(rzip_control *control); extern void zpaq_compress(uchar *c_buf, long long *c_len, uchar *s_buf, long long s_len, int level); +extern void zpaq_decompress(uchar *s_buf, long long *d_len, uchar *c_buf, long long c_len); #endif diff --git a/stream.c b/stream.c index 61962c5..a1f00ed 100644 --- a/stream.c +++ b/stream.c @@ -538,7 +538,36 @@ out_free: try to decompress a buffer. Return 0 on success and -1 on failure. */ +static int zpaq_decompress_buf(rzip_control *control __UNUSED__, struct uncomp_thread *ucthread, long thread) +{ + i64 dlen = ucthread->u_len; + uchar *c_buf; + int ret = 0; + c_buf = ucthread->s_buf; + ucthread->s_buf = malloc(dlen); + if (unlikely(!ucthread->s_buf)) { + print_err("Failed to allocate %ld bytes for decompression\n", dlen); + ret = -1; + goto out; + } + + dlen = 0; + zpaq_decompress(ucthread->s_buf, &dlen, c_buf, ucthread->c_len); + + if (unlikely(dlen != ucthread->u_len)) { + print_err("Inconsistent length after decompression. Got %ld bytes, expected %lld\n", dlen, ucthread->u_len); + ret = -1; + } + + free(c_buf); +out: + if (ret == -1) + ucthread->s_buf = c_buf; + return ret; +} + +#if 0 static int zpaq_decompress_buf(rzip_control *control, struct uncomp_thread *ucthread, long thread) { uchar *c_buf = NULL; @@ -578,6 +607,7 @@ static int zpaq_decompress_buf(rzip_control *control, struct uncomp_thread *ucth return 0; } +#endif static int bzip2_decompress_buf(rzip_control *control __UNUSED__, struct uncomp_thread *ucthread) {