diff options
Diffstat (limited to 'src/modules/common/bz2comprs.cpp')
-rw-r--r-- | src/modules/common/bz2comprs.cpp | 57 |
1 files changed, 14 insertions, 43 deletions
diff --git a/src/modules/common/bz2comprs.cpp b/src/modules/common/bz2comprs.cpp index 7863e98..6b9374e 100644 --- a/src/modules/common/bz2comprs.cpp +++ b/src/modules/common/bz2comprs.cpp @@ -3,7 +3,7 @@ * bz2comprs.cpp - Bzip2Compress, a driver class that provides bzip2 * compression (Burrows–Wheeler with Huffman coding) * - * $Id: bz2comprs.cpp 3156 2014-04-17 03:50:37Z greg.hellings $ + * $Id: bz2comprs.cpp 3515 2017-11-01 11:38:09Z scribe $ * * Copyright 2000-2014 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society @@ -26,7 +26,7 @@ #include <string.h> #include <stdio.h> #include <bz2comprs.h> -#include <zlib.h> +#include <bzlib.h> SWORD_NAMESPACE_START @@ -36,6 +36,7 @@ SWORD_NAMESPACE_START */ Bzip2Compress::Bzip2Compress() : SWCompress() { + level = 9; } @@ -59,20 +60,6 @@ Bzip2Compress::~Bzip2Compress() { void Bzip2Compress::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 - 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. -*/ direct = 0; // set direction needed by parent [Get|Send]Chars() // get buffer @@ -91,12 +78,12 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, } - zlen = (long) (len*1.001)+15; + zlen = (long) (len*1.01)+600; char *zbuf = new char[zlen+1]; if (len) { //printf("Doing compress\n"); - if (compress((Bytef*)zbuf, &zlen, (const Bytef*)buf, len) != Z_OK) + if (BZ2_bzBuffToBuffCompress(zbuf, (unsigned int*)&zlen, buf, (unsigned int)len, level, 0, 0) != BZ_OK) { printf("ERROR in compression\n"); } @@ -123,23 +110,7 @@ ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, void Bzip2Compress::Decode(void) { -/* -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); - Decompresses 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 large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - This function can be used to decompress a whole file at once if the - input file is mmap'ed. - - uncompress 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, 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]; @@ -147,7 +118,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) @@ -158,16 +129,16 @@ ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, //printf("Decoding complength{%ld} uncomp{%ld}\n", zlen, blen); if (zlen) { - unsigned long blen = zlen*20; // trust compression is less than 1000% + unsigned int blen = (unsigned int)(zlen*20); // trust compression is less than 1000% char *buf = new char[blen]; //printf("Doing decompress {%s}\n", zbuf); slen = 0; - switch (uncompress((Bytef*)buf, &blen, (Bytef*)zbuf, zlen)){ - case Z_OK: SendChars(buf, blen); slen = blen; break; - 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; + switch (BZ2_bzBuffToBuffDecompress(buf, &blen, zbuf, (unsigned int)zlen, 0, 0)){ + case BZ_OK: SendChars(buf, blen); slen = blen; break; + case BZ_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression.\n"); break; + case BZ_OUTBUFF_FULL: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression.\n"); break; + case BZ_DATA_ERROR: fprintf(stderr, "ERROR: corrupt data during decompression.\n"); break; + default: fprintf(stderr, "ERROR: an unknown error occurred during decompression.\n"); break; } delete [] buf; } |