code review

This commit is contained in:
Seth Alves 2015-08-05 10:16:45 -07:00
parent 45643a3aad
commit eb87023416
2 changed files with 11 additions and 3 deletions

View file

@ -14,6 +14,7 @@
const int GZIP_WINDOWS_BIT = 31;
const int GZIP_CHUNK_SIZE = 4096;
const int DEFAULT_MEM_LEVEL = 8;
bool gunzip(QByteArray source, QByteArray &destination) {
destination.clear();
@ -100,10 +101,10 @@ bool gzip(QByteArray source, QByteArray &destination, int compressionLevel) {
strm.avail_in = 0;
int status = deflateInit2(&strm,
qMax(-1, qMin(9, compressionLevel)),
qMax(Z_DEFAULT_COMPRESSION, qMin(9, compressionLevel)),
Z_DEFLATED,
GZIP_WINDOWS_BIT,
8,
DEFAULT_MEM_LEVEL,
Z_DEFAULT_STRATEGY);
if (status != Z_OK) {
return false;

View file

@ -14,7 +14,14 @@
#include <QByteArray>
bool gzip(QByteArray source, QByteArray &destination, int compressionLevel = -1);
// The compression level must be Z_DEFAULT_COMPRESSION (-1), or between 0 and
// 9: 1 gives best speed, 9 gives best compression, 0 gives no
// compression at all (the input data is simply copied a block at a
// time). Z_DEFAULT_COMPRESSION requests a default compromise between
// speed and compression (currently equivalent to level 6).
bool gzip(QByteArray source, QByteArray &destination, int compressionLevel = -1); // -1 is Z_DEFAULT_COMPRESSION
bool gunzip(QByteArray source, QByteArray &destination);
#endif