Compress GZip and ZLib

sioconcept

Active Member
Licensed User
Longtime User
[CLOSED]

Hi,

I've a little problem with compress method. (This string is B64 encoded to compare it easly)

Look this :

B4A: SIlzdHJ2cXUDAAV+AZY=
PHP: eJxzdHJ2cXUDAAV+AZY=

B4A: H4sIAAAAAAAAAHN0cnZxdQMAaf52uwYAAAA=
PHP: H4sIAAAAAAAAA3N0cnZxdQMAaf52uwYAAAA=

The first line is compressed with ZLib and the 2nd GZip.
I don't know why, the result is different between B4A and PHP... However, the string encoded with B4A is decoded fine by PHP, but not in PHP to B4A.

Can you help me ? Thanks :sign0163:
 
Last edited:

sioconcept

Active Member
Licensed User
Longtime User
Of course Erel.

In PHP :
echo base64_encode(gzcompress('ABCDEF')); // Zlib
echo base64_encode(gzencode('ABCDEF')); // GZip

In B4A :
Dim CS As CompressedStreams
Dim SU As StringUtils
Dim Tools() As Byte
Dim Data = "ABCDEF" as String

Tools = Data.GetBytes("UTF8")
Tools = CS.CompressBytes(Tools, "zlib") ' change to gzip next
log(SU.EncodeBase64(Tools).Replace(Chr(32), Chr(43)))
 
Last edited:
Upvote 0

sioconcept

Active Member
Licensed User
Longtime User
Another example PHP vs B4A with a bigger string. As first time in GZip, only 1 byte is different :

See (it's Amazing ;-)

PHP :
H4sIAAAAAAAAA01T247TQAz9FX/AJJtbl3aeQLCAxAvSIvZhxYOTuKlhMhPmsmxZ7b/jpE2L8pDR2D4+53j8wr0u1c/grJ86XeWFii6ikTtPIZmoH1+WjCHJr9+UBdblPtvVZZk1DTVZW26KDGssi23XtLS7VRN3MXnShxgnfXMzGezo4Eyfc7ypq+e6UjiQrgtlcST9hceWvDnCJzStR44HNZDtyes9jWhIdW6c0B71ezKDRzUdnCW9Ld9km81tVtXlVkkeG/3rDPS2WxJzqVPY96Ii6LLZNTsFd+YrBqfgs/MY2cF99EQxKGxdivojdmw4MEQC7Lo0BrSAhn8nnk5/HEHQSMETGY6wXwt6lkjvjPMEFNV6dL30+O+cw9pCQWvQ9oLBVsC8g0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d4b/YkvxIAuC1tDxVc3R6hS9d3tGeKB2pnSK1KfIO3lQR3jAo6XXH/L9A78Rjjw=
B4A
SIlNU9uO00AM/RV/wCSbW5d2nkCwgMQL0iL2YcWDk7ipYTIT5rJsWe2/46RNi/KQ0dg+Pud4/MK9LtXP4KyfOl3lhYouopE7TyGZqB9flowhya/flAXW5T7b1WWZNQ01WVtuigxrLItt17S0u1UTdzF50ocYJ31zMxns6OBMn3O8qavnulI4kK4LZXEk/YXHlrw5wic0rUeOBzWQ7cnrPY1oSHVunNAe9Xsyg0c1HZwlvS3fZJvNbVbV5VZJHhv96wz0tlsSc6lT2PeiIuiy2TU7BXfmKwan4LPzGNnBffREMShsXYr6I3ZsODBEAuy6NAa0gIZ/J55OfxxB0EjBExmOsF8LepZI74zzBBTVenS99PjvnMPaQkFr0PaCwVbAvINAPYzOUIgs+GxMGiGk0PEkSZQ4jK6HJ2dSnDCCdSH61F86WQ5GLm0ax2MOH3iQi8DCSQqVUII465VWyUxJzgRBYOfGCka2krmnNDBeNQUw6GZ3YMTBooIU55oc7s5cLLcHOMikPHkWzexZhr50FD9WAjyFtNK4yFlKV7vSYs2qJIfvZGc3/8y+XuCBnsl3YhumSCNMHimQjZfprM4tRiiQOxG34ES2Hfdpzu2luTCwA4ju2RYEm4zBlcpV+omRDBnkhcYr+hXsOqpFzMJ2OXXOBpKXIk7dU38CmdH/ZyL2L6ar6wu6TBbTkM7h89ByWcSBQyRPsoe7XZMV26zafqtqXW50cwtZUelC1haHoB+vEzFpEoAkSyAa1ExOzTQVzZ3Pz/mH2nuWirBu+bKSd4b/YkvxIAuC1tDxVc3R6hS9d3tGeKB2pnSK1KfIO3lQR3jAo6XXH/L9A78Rjjw=

To resume it; only 1 octet change with GZip in octet 14 and the first 3 octets change with ZLib whatever the length of the string.
 
Last edited:
Upvote 0
Top