You will need to send the length of the gthe string or close the connection so that you know where the last byte is located.
The most likely class that will help you is DeflatorInputStream, which will be used after the bytes are read. This is a clean wrapper for the zlib class. I have not tested it with python, but this is the best option.
You can try other compressions, such as Snappy or LZ4, which support cross-platform.
source share