Deflate / Deflate_compress yields different result

Doubts, help and support about QuickBMS and other game research tools
LostMahPants
Posts: 2
Joined: Thu Oct 12, 2017 5:59 pm

Deflate / Deflate_compress yields different result

Post by LostMahPants »

So, decompressing and compressing result back with Deflate gives different result. Which makes me think i'm missing something.

Code: Select all

comtype deflate

math SIZE = 32
math ZSIZE = 26

clog MEMORY_FILE 0 ZSIZE SIZE
log Decompressed.pak 0 SIZE MEMORY_FILE

comtype deflate_compress
clog MEMORY_FILE2 0 ZSIZE SIZE MEMORY_FILE
log Recompressed.pak 0 ZSIZE MEMORY_FILE2

comtype deflate
clog DecompressedX2.pak 0 ZSIZE SIZE MEMORY_FILE2

example's just a 26 bytes, decompresses to 32 fine.
However, recompressing it back gives result different from original one and decompressing it once more loses 6 bytes.

Am I just monumentally retarded and missed something obvious or is it just the intended behavior by design?
Thanks in advance for explanation.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Deflate / Deflate_compress yields different result

Post by aluigi »

You made a mistake, check the lines with the "here" comment:

Code: Select all

comtype deflate

math SIZE = 32
math ZSIZE = 26

clog MEMORY_FILE 0 ZSIZE SIZE
log Decompressed.pak 0 SIZE MEMORY_FILE

comtype deflate_compress
clog MEMORY_FILE2 0 SIZE SIZE MEMORY_FILE   # here
get ZSIZE asize MEMORY_FILE2                # here
log Recompressed.pak 0 ZSIZE MEMORY_FILE2

comtype deflate
clog DecompressedX2.pak 0 ZSIZE SIZE MEMORY_FILE2

And yes it's perfectly normal that different implementations of a compression algorithm or different settings produce different compressed results, it's a boring problem which is well known by the users who use the reimporting method with an untouched file to reimport occupies more bytes than the original one even if it's the same.
LostMahPants
Posts: 2
Joined: Thu Oct 12, 2017 5:59 pm

Re: Deflate / Deflate_compress yields different result

Post by LostMahPants »

Thank you a lot!
I bet in documentation there's a a good chunky reminder about how to avoid this kind of amateur mistakes, heh. Should've read it more thoroughly before asking...
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Deflate / Deflate_compress yields different result

Post by aluigi »

Don't worry that's ok, feel free to ask everytime you need.