I am using the following lines in my code:
payloadByte = zlib.compress(str.encode("hello"))
print(zlib.decompress(payloadByte[0:4]))
However, zlib throws the following error:
zlib.error: Error -5 while decompressing data: incomplete or truncated stream
I need to use byte slicing techniques due to the fact that I have to decompress from a specific point in a large byte array. I have created this byte array using a struct, like so:
messageIdByte = struct.pack("i", int(messageId))
payloadByte = zlib.compress(str.encode("hello"))
return messageIdByte + payloadByte
In this example, I have already unpacked the struct like so:
messageId = struct.unpack("i", bytes[0:4])[0]
Now, I need to decompress the string from the byte array, but getting the specific bytes [4:8] yields this error.