summaryrefslogtreecommitdiff
path: root/distfoldd/compressor.cc
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-09-30 19:41:17 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-09-30 19:41:17 +0200
commit15253d1995ea49b114ef5c627e15b661dbd602b2 (patch)
tree1111441406a0b043f45ab19fe42e567be36d4d09 /distfoldd/compressor.cc
parentc8f89279026af6bb03ef3d66e44e859fb7208925 (diff)
downloaddistfold-15253d1995ea49b114ef5c627e15b661dbd602b2.tar.gz
distfold-15253d1995ea49b114ef5c627e15b661dbd602b2.zip
add some trivial authentication
Diffstat (limited to 'distfoldd/compressor.cc')
-rw-r--r--distfoldd/compressor.cc81
1 files changed, 2 insertions, 79 deletions
diff --git a/distfoldd/compressor.cc b/distfoldd/compressor.cc
index 98eaa92..1e42446 100644
--- a/distfoldd/compressor.cc
+++ b/distfoldd/compressor.cc
@@ -1,6 +1,5 @@
#include <QtCore/QDebug>
-#include <zlib.h>
#include "compressor.h"
Compressor::Compressor()
@@ -9,86 +8,10 @@ Compressor::Compressor()
QByteArray Compressor::compress(const QByteArray& data)
{
- if (data.isEmpty()) return data;
-
- QByteArray in = data, out;
- z_stream strm;
- int ret;
-
- memset(&strm, 0, sizeof(strm));
- out.resize(qMax(in.size(), 1024));
-
- strm.avail_in = in.size();
- strm.next_in = reinterpret_cast<Bytef*>(in.data());
- strm.avail_out = out.size();
- strm.next_out = reinterpret_cast<Bytef*>(out.data());
-
- ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION);
- if (ret != Z_OK) {
- qWarning() << "deflateInit failed";
- return data;
- }
-
- do {
- if (strm.avail_out == 0) {
- int cur_size = out.size();
- out.resize(cur_size * 2);
- strm.avail_out = cur_size;
- strm.next_out = reinterpret_cast<Bytef*>(&out.data()[cur_size]);
- }
- ret = deflate(&strm, Z_FINISH);
- } while (ret == Z_OK || ret == Z_BUF_ERROR);
-
- Q_ASSERT(ret == Z_STREAM_END);
- Q_ASSERT(strm.avail_in == 0);
- if (strm.avail_out > 0) {
- out.resize(out.size() - strm.avail_out);
- }
-
- deflateEnd(&strm);
-
- return out;
+ return qCompress(data);
}
QByteArray Compressor::decompress(const QByteArray& data)
{
- if (data.isEmpty()) return data;
-
- QByteArray in = data, out;
- z_stream strm;
- int ret;
-
- memset(&strm, 0, sizeof(strm));
- out.resize(qMax(static_cast<int>(in.size() * 1.5), 1024));
-
- strm.avail_in = in.size();
- strm.next_in = reinterpret_cast<Bytef*>(in.data());
- strm.avail_out = out.size();
- strm.next_out = reinterpret_cast<Bytef*>(out.data());
-
- ret = inflateInit(&strm);
- if (ret != Z_OK) {
- qWarning() << "inflateInit failed";
- return data;
- }
-
- do {
- if (strm.avail_out == 0) {
- int cur_size = out.size();
- out.resize(cur_size * 2);
- strm.avail_out = cur_size;
- strm.next_out = reinterpret_cast<Bytef*>(&out.data()[cur_size]);
- }
- ret = inflate(&strm, Z_FINISH);
- } while (ret == Z_OK || ret == Z_BUF_ERROR);
-
- Q_ASSERT(ret == Z_STREAM_END);
- Q_ASSERT(strm.avail_in == 0);
- if (strm.avail_out > 0) {
- out.resize(out.size() - strm.avail_out);
- }
-
- inflateEnd(&strm);
-
- return out;
+ return qUncompress(data);
}