Use libzpaq backend for decompression.

This commit is contained in:
Con Kolivas 2012-03-16 14:14:22 +11:00
parent f8d05b9a66
commit a55250cf16
3 changed files with 38 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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)
{