summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <Pixel>2001-12-03 11:39:34 +0000
committerPixel <Pixel>2001-12-03 11:39:34 +0000
commit8fac2c6298c5fd2b06e7e219687766dd8cf965b3 (patch)
tree6dc9ec0dc0d6a24e528ab67dc7081d069080f1ee
parent84944dbe0dfcadfb5c069e210c0545b88aae57dc (diff)
Zlib....
-rw-r--r--configure.in1
-rw-r--r--include/Buffer.h7
-rw-r--r--include/CopyJob.h2
-rw-r--r--lib/Buffer.cc43
-rw-r--r--lib/CopyJob.cc2
5 files changed, 51 insertions, 4 deletions
diff --git a/configure.in b/configure.in
index e587dad..f94efba 100644
--- a/configure.in
+++ b/configure.in
@@ -80,6 +80,7 @@ AC_CHECK_FUNCS(getcwd getwd putenv strdup memmove memset select poll)
AC_CHECK_FUNCS(strerror strrchr strstr mempcpy nl_langinfo strcspn)
AC_SEARCH_LIBS(socket,socket)
AC_SEARCH_LIBS(gethostbyname,nsl)
+AC_SEARCH_LIBS(deflate,z)
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_VPRINTF
diff --git a/include/Buffer.h b/include/Buffer.h
index c2e78ec..5177916 100644
--- a/include/Buffer.h
+++ b/include/Buffer.h
@@ -2,6 +2,7 @@
#define __BUFFER_H__
#ifdef __cplusplus
+#include <zlib.h>
#include <Exceptions.h>
#include <Handle.h>
@@ -18,12 +19,14 @@ class Buffer : public Handle {
virtual bool CanRead();
virtual bool CanWrite();
virtual String GetName();
- Buffer operator=(const Buffer &);
+ virtual Buffer operator=(const Buffer &);
virtual bool CanWatch();
+ void deflate(void) throw (GeneralException);
private:
- char * buffer;
+ char * buffer, * zbuffer;
int realsiz, bufsiz, ptr;
+ z_stream zs;
};
#else
diff --git a/include/CopyJob.h b/include/CopyJob.h
index bd859bb..14fbf0b 100644
--- a/include/CopyJob.h
+++ b/include/CopyJob.h
@@ -9,7 +9,7 @@
class CopyJob : public Task {
public:
- CopyJob(Handle *, Handle *, ssize_t = -1, bool = false);
+ CopyJob(Handle *, Handle *, ssize_t = -1, bool = false, int z = 0);
virtual ~CopyJob();
virtual int Do() throw (GeneralException);
virtual String GetName();
diff --git a/lib/Buffer.cc b/lib/Buffer.cc
index 2c2c955..2318f08 100644
--- a/lib/Buffer.cc
+++ b/lib/Buffer.cc
@@ -75,3 +75,46 @@ Buffer Buffer::operator=(const Buffer & b) {
bool Buffer::CanWatch() {
return false;
}
+
+void Buffer::deflate(void) throw (GeneralException) {
+ int err;
+
+ if (ptr) {
+ throw GeneralException(_("Can't deflate: buffer has already been read"));
+ }
+
+ err = deflateInit(&zs, Z_BEST_COMPRESSION);
+ if (err != Z_OK) {
+ throw GeneralException(String(_("Can't init Zlib: ")) + zs.msg);
+ }
+
+ zbuffer = (char *) malloc(realsiz);
+
+ zs.next_in = (Bytef *) buffer;
+ zs.avail_in = realsiz;
+ zs.next_out = (Bytef *) zbuffer;
+ zs.avail_out = realsiz;
+ zs.zalloc = Z_NULL;
+ zs.zfree = Z_NULL;
+ zs.opaque = Z_NULL;
+
+ err = ::deflate(&zs, Z_FINISH);
+
+ if (err != Z_STREAM_END) {
+ throw GeneralException(String(_("Error during deflate: ")) + zs.msg);
+ }
+
+ err = deflateEnd(&zs);
+ if (err != Z_OK) {
+ throw GeneralException(String(_("Error during deflateEnd: ")) + zs.msg);
+ }
+
+ free(buffer);
+ buffer = zbuffer;
+
+ realsiz = zs.total_out;
+
+ int numblocks = realsiz / realloc_threshold;
+ int remains = realsiz % realloc_threshold;
+ buffer = (char *) realloc(buffer, bufsiz = ((numblocks + (remains ? 1 : 0)) * realloc_threshold));
+}
diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc
index 864706b..8524b17 100644
--- a/lib/CopyJob.cc
+++ b/lib/CopyJob.cc
@@ -2,7 +2,7 @@
#include "General.h"
#include "config.h"
-CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads) : s(as), d(ad), ds(ads), siz(asiz), cursiz(0), r(0) {
+CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, int az) : s(as), d(ad), ds(ads), siz(asiz), cursiz(0), r(0) {
s->SetNonBlock();
d->SetNonBlock();
WaitFor(s, W4_READING);