I am trying to compress a string in Python, but my result is not what I expected.
The string I am trying to compress for example:
<?xml version='1.0' encoding='UTF-8'?>
Here is what my end result should be:
H4sIAAAAAAAA/7Oxr8jNUShLLSrOzM+zVTfUM1BXSM1Lzk/JzEu3VQ8NcdO1ULe3AwBHQvxaJgAAAA==
First try:
base64.b64encode(gzip.compress("<?xml version='1.0' encoding='UTF-8'?>".encode('utf-8')))
Results in:
b'H4sIAHDj6lsC/7Oxr8jNUShLLSrOzM+zVTfUM1BXSM1Lzk/JzEu3VQ8NcdO1ULe3AwBHQvxaJgAAAA=='
The result is almost what I am looking for, but the header part is different. Both results (my one and the expected one) decompress to the same string, so they both seem to work. I still would like to know why I am not getting the correct header in the base64 compressed string.
Could I maybe get a better result using zlib? I tried, but got a completely different result, which worked when decompressed, too.