What's the quickest way in python to determine if a string was compressed by zlib. I am using this currently.
def iscompressed(data):
result = True
try:
s =zlib.decompress(data)
except:
result = False
return result
I am sure there is a more elegant way.
Use mb_check_encoding to see whether a string is valid in the encoding you suspect it to be in. If it isn't, it's probably compressed (or you checked for the wrong encoding). With the caveat that virtually any byte sequence is valid in virtually every single-byte encoding, so this'll only work for multi-byte encodings.
Arm throughput (MB/s, higher is better): At level 6, zlib-cloudflare is, on average, 90 percent faster in compression operations than zlib-madler. zlib-cloudflare is, on average, 52 percent faster in decompression operations than zlib-madler.
As of September 2018, zlib only supports one algorithm, called DEFLATE, which uses a combination of a variation of LZ77 (Lempel–Ziv 1977) and Huffman coding. This algorithm provides good compression on a wide variety of data with minimal use of system resources.
zlib is a free, open-source software for the compression and decompression of files. Additionally, it comes under the lossless data compression category.
You can check the first 2 Byte for the header information - it is, however, not 100% safe.
See http://www.faqs.org/rfcs/rfc1950.html, chapter 2.2
While the only way to be 100% sure is to actually try to decompress it, you can make a reasonable guess by looking for the zlib compression method + flags header bits:
http://www.faqs.org/rfcs/rfc1950.html
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