1# Copyright (C) 2011  Jeff Forcier <jeff@bitprophet.org>
2#
3# This file is part of ssh.
4#
5# 'ssh' is free software; you can redistribute it and/or modify it under the
6# terms of the GNU Lesser General Public License as published by the Free
7# Software Foundation; either version 2.1 of the License, or (at your option)
8# any later version.
9#
10# 'ssh' is distrubuted in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
13# details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with 'ssh'; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA.
18
19"""
20Compression implementations for a Transport.
21"""
22
23import zlib
24
25
26class ZlibCompressor (object):
27    def __init__(self):
28        self.z = zlib.compressobj(9)
29
30    def __call__(self, data):
31        return self.z.compress(data) + self.z.flush(zlib.Z_FULL_FLUSH)
32
33
34class ZlibDecompressor (object):
35    def __init__(self):
36        self.z = zlib.decompressobj()
37
38    def __call__(self, data):
39        return self.z.decompress(data)
40