Snappy is a fast compression algorithm by Google. When I’ve used it, it’s been for socket compression, though it can be used for file compression, too.
For socket compression in Python, the examples are embarrassingly simple. First, import the module:
When you establish the socket (which we’ll refer to as
s), create the compressor and decompressor:
c = snappy.StreamCompressor() d = snappy.StreamDecompressor()
From that point on, just pass all of your outgoing data through
c.add_chunk(), and all of your read data through
decompress() may return an empty string from time-to-time (obviously).