ZLib

BlitzMax Forums/BlitzMax Programming/ZLib

Tricky(Posted 2011) [#1]
I've been trying to play around with the Pub.ZLib module for my next project, but something appears wrong here.


Global Bank1:TBank = LoadBank("/Volumes/AZIELLA/TricFAQ/HTML/wild arms 5 - Walkthrough.html")
'Global Bank2:TBank  ' If it all worked this would be my Bank to store the result in.
Global Pointer1:Byte Ptr = BankBuf(Bank1)
Global Pointer2:Byte Ptr
Global DestSize = Bank1.Size()*2     ' Making sure the compress buffer is big enough

Print compress(Pointer2,DestSize,Pointer1,Bank1.Size())


The used file is a walkthrough for 'Wild Arms 5' I wrote in HTML, but that's not relevant, the routine has been used on multiple files with the same result. This program resulted to me always into giving the error code -2. I've been digging through the ZLib mode (as the BMax documentation on this mod is ... shall we say... poor) and -2 appears to mean that ZLib doesn't understand the compression method. Now I wonder, is this a bug in ZLib, in the BMax Mod or am I doing something wrong here?

Of course, this has now only been tested on a MacMini PPC, I haven't yet tried any other platforms, but I don't expect much difference there.

Any ideas?


Noobody(Posted 2011) [#2]
Zlib is not going to allocate the destination buffer for you - you're supposed to do that. Pointer2 should contain the already allocated destination buffer in this case, and DestSize should contain the amount of bytes you allocated for the destination buffer.
Also, you should pass VarPtr DestSize, not DestSize - compress is going to overwrite the value in DestSize with the actual size of the compressed data, but that's only possible if you pass the pointer of the variable and not the value of it.

How many bytes you should allocate for the destination buffer is up to you - the compressed data is never going to be (much) bigger than the source data, so if you allocate a buffer of the same size as the source buffer, you're probably going to be fine. If that is not an option (let's say your source buffer is really big), you could try wrapping the compressBound function from Zlib, which will tell you how many bytes it's going to need at most for the compressed data.


Tricky(Posted 2011) [#3]
Hey thanks.... it worked! :)


ImaginaryHuman(Posted 2011) [#4]
Try using LZMA, it's faster and compresses better. There's a module in the code archives.

Last edited 2011