Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: CBXE8 - Decompressing ZLIB v1.2.3 with TIdCompressorZLib ?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: May 7, 2015 8:23 PM Last Post By: GAI CHEW KAI
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
CBXE8 - Decompressing ZLIB v1.2.3 with TIdCompressorZLib ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 27, 2015 1:03 AM
I am using Embarcadero® C++Builder XE8 Version 22.0.19027.8951,

I have a compressed data stream using ZLIB version 1.2.3, July 18th, 2005 and version 1.2.8, April 28th, 2013 by Jean-loup Gailly and Mark Adler such as:

::compress( abBuf, &dwCompressLen, (unsigned char*)pcIn, n );

When the Decompression process carried out, it breaks at:

class procedure EZlibError.RaiseException(const AError: Integer);
var
LException: EZlibError;
begin
LException := CreateFmt(sZLibError, [AError]);
LException.FErrorCode := AError;
raise LException;
end;

and the Event Log:

First chance exception at $53666C8F. Exception class EDecompressionError with message 'ZLib Error (-3)'. Process MiBoxClient.apk (16302)

from ZLIB.H of version 1.2.3:

#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)

under compress.c:
/* ===========================================================================
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 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed 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.
*/
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;

stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;

stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;

err = deflateInit(&stream, level);
if (err != Z_OK) return err;

err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;

err = deflateEnd(&stream);
return err;
}

/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}

QUESTIONS:

1. How do I decompress data stream using TIdCompressorZLib as DecompressGZipStream() cannot works, obviously data stream is not compressed using GZIP format initially ?

2. I also tried the DecompressDeflateStream( compressed, so ) method but also resulted the same error.

3. What is "AWindowBits" under IdCompressorZlib.hpp as shown below ?

virtual void __fastcall DecompressStream(System::Classes::TStream* AInStream, System::Classes::TStream* AOutStream, const int AWindowBits);

4. It is correct to refer to legacy ZLIB.H error code where -3 is Z_DATA_ERROR where from Event Log indicated 'ZLib Error (-3)' ?

Any hint or suggestion is greatly appreciated :o)

Please advise.
GAI CHEW KAI

Posts: 117
Registered: 7/25/14
Re: CBXE8 - Decompressing ZLIB v1.2.3 with TIdCompressorZLib ?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 30, 2015 1:15 AM   in response to: GAI CHEW KAI in response to: GAI CHEW KAI
I just found out the ZLIB source code can be compiled for Android development.

NOTE: I am using ZLIB v1.2.8 to describe the software compile for Android platform.

1. In my case, I merely use compress() and uncompress() so include the following files into your project will be sufficient.

adler32.c
compress.c
crc32.c
crc32.h
crypt.h
deflate.c
deflate.h
infback.c
inffast.c
inffast.h
inffixed.h
inflate.c
inflate.h
inftrees.c
inftrees.h
trees.c
trees.h
uncompr.c
zconf.h
zlib.h
zutil.c
zutil.h

2. If you try to compile, you will encounter the following error:

[bccaarm Fatal Error] gzguts.h(35): 'io.h' file not found

- Go to gzguts.h, and add in new directive line: "#if !defined(__ANDROID__) && defined(_Windows) && defined(_WINDOWS)" as shown below.

#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32)
#if !defined(__ANDROID__) && defined(_Windows) && defined(_WINDOWS)
#include <io.h>
#endif
#endif

- You should be able to compile properly then.

Edited by: GAI CHEW KAI on May 7, 2015 8:22 PM
Added defined(_WINDOWS) for compiling in Microsoft Visual C++
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02