summaryrefslogtreecommitdiff
path: root/lib/Handle.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Handle.cc')
-rw-r--r--lib/Handle.cc53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc
index 56e6c62..3e437a3 100644
--- a/lib/Handle.cc
+++ b/lib/Handle.cc
@@ -21,6 +21,7 @@
#include <string.h>
#include <errno.h>
#include <fcntl.h>
+#include <ucl/ucl.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -870,3 +871,55 @@ int Handle::zlib_deflate(Handle * in, Handle * out) throw (GeneralException) {
return total_out;
}
+
+int Handle::ucl_compress(Handle * in, Handle * out) throw (GeneralException) {
+ if (ucl_init() != UCL_E_OK)
+ throw GeneralException("ucl_init failed");
+
+ unsigned char * b_in, * b_out;
+ unsigned int len_in, len_out;
+
+ len_in = in->GetSize();
+ len_out = len_in + len_in / 8 + 256;
+
+ b_in = (unsigned char *) malloc(len_in);
+ b_out = (unsigned char *) malloc(len_out);
+ in->read(b_in, len_in);
+
+ int r = ucl_nrv2e_99_compress(b_in, len_in, b_out, &len_out, NULL, 10, NULL, NULL);
+ if (r != UCL_E_OK)
+ throw GeneralException("Error happened during ucl_nrv2b_99_compress");
+
+ out->write(b_out, len_out);
+
+ free(b_out);
+ free(b_in);
+
+ return len_out;
+}
+
+int Handle::ucl_decompress(Handle * in, Handle * out) throw (GeneralException) {
+ if (ucl_init() != UCL_E_OK)
+ throw GeneralException("ucl_init failed");
+
+ unsigned char * b_in, * b_out;
+ unsigned int len_in, len_out;
+
+ len_in = in->GetSize();
+ len_out = len_in + len_in / 8 + 256;
+
+ b_in = (unsigned char *) malloc(len_in);
+ b_out = (unsigned char *) malloc(len_out);
+ in->read(b_in, len_in);
+
+ int r = ucl_nrv2e_decompress_8(b_in, len_in, b_out, &len_out, NULL);
+ if (r != UCL_E_OK)
+ throw GeneralException("Error happened during ucl_nrv2b_decompress_32");
+
+ out->write(b_out, len_out);
+
+ free(b_out);
+ free(b_in);
+
+ return len_out;
+}