I'm using compression_encode_buffer
with COMPRESSION_ZLIB
to zlib-compress data in an iOS app, but the result is missing the zlib header.
For example:
size = compression_encode_buffer(
destinationBuffer, destinationBufferSize,
sourceBuffer, sourceBufferSize, nil,
COMPRESSION_ZLIB
)
Will return the bytes:
AD 53 C1 8E 9B 30 …
While using, for example, Python's data.encode("zlib")
on the same data will return:
78 9C AD 53 C1 8E 9B 30 …
^^ ^^ correct zlib header
What's up with that? Why isn't the header being included? And is there a "correct" way to add it?
The two bytes are a zlib header, not a magic number. Most likely you are missing the final 4 bytes of the stream (the ADLER32 checksum) as well, and only have the "deflate" datastream that you expected to be wrapped in a zlib datatstream. The iOS documentation says as much:
ZLIB
The encoded format is the raw DEFLATE format as described
in IETF RFC 1951 Using the ZLIB library
They should have called the compression method "DEFLATE" not "ZLIB".
See this related question about dealing with ZLIB vs DEFLATE data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With