summaryrefslogtreecommitdiff
path: root/src/modules/common/zipcomprs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/common/zipcomprs.cpp')
-rw-r--r--src/modules/common/zipcomprs.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/modules/common/zipcomprs.cpp b/src/modules/common/zipcomprs.cpp
index 28471d8..557239e 100644
--- a/src/modules/common/zipcomprs.cpp
+++ b/src/modules/common/zipcomprs.cpp
@@ -3,7 +3,7 @@
* zipcomprs.cpp - ZipCompress, a driver class that provides zlib
* compression
*
- * $Id: zipcomprs.cpp 3175 2014-04-17 04:21:31Z greg.hellings $
+ * $Id: zipcomprs.cpp 3515 2017-11-01 11:38:09Z scribe $
*
* Copyright 2000-2014 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
@@ -38,6 +38,7 @@ SWORD_NAMESPACE_START
ZipCompress::ZipCompress() : SWCompress()
{
// fprintf(stderr, "init compress\n");
+ level = Z_DEFAULT_COMPRESSION;
}
@@ -62,18 +63,20 @@ ZipCompress::~ZipCompress() {
void ZipCompress::Encode(void)
{
/*
-ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
- const Bytef *source, uLong sourceLen));
- Compresses the source buffer into the destination buffer. sourceLen is
- the byte length of the source buffer. Upon entry, destLen is the total
- size of the destination buffer, which must be at least 0.1% larger than
- sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen,
+ int level));
+
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
compressed buffer.
- This function can be used to compress a whole file at once if the
- input file is mmap'ed.
- compress returns Z_OK if success, Z_MEM_ERROR if there was not
- enough memory, Z_BUF_ERROR if there was not enough room in the output
- buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
*/
direct = 0; // set direction needed by parent [Get|Send]Chars()
@@ -98,7 +101,7 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
if (len)
{
//printf("Doing compress\n");
- if (compress((Bytef*)zbuf, &zlen, (const Bytef*)buf, len) != Z_OK)
+ if (compress2((Bytef*)zbuf, &zlen, (const Bytef*)buf, len, level) != Z_OK)
{
printf("ERROR in compression\n");
}
@@ -142,6 +145,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
+ direct = 1; // set direction needed by parent [Get|Send]Chars()
// get buffer
char chunk[1024];
@@ -149,7 +153,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
char *chunkbuf = zbuf;
int chunklen;
unsigned long zlen = 0;
- while((chunklen = GetChars(chunk, 1023))) {
+ while((chunklen = (int)GetChars(chunk, 1023))) {
memcpy(chunkbuf, chunk, chunklen);
zlen += chunklen;
if (chunklen < 1023)
@@ -169,7 +173,7 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
case Z_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression.\n"); break;
case Z_BUF_ERROR: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression.\n"); break;
case Z_DATA_ERROR: fprintf(stderr, "ERROR: corrupt data during decompression.\n"); break;
- default: fprintf(stderr, "ERROR: an unknown error occured during decompression.\n"); break;
+ default: fprintf(stderr, "ERROR: an unknown error occurred during decompression.\n"); break;
}
delete [] buf;
}