diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Buffer.cc | 43 | ||||
-rw-r--r-- | lib/CopyJob.cc | 2 |
2 files changed, 44 insertions, 1 deletions
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); |