Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bz2
- import shutil
- class Compander(object):
- def __init__(self, uncompressed_name, compressed_name):
- self.uncompressed_name = uncompressed_name
- self.compressed_name = compressed_name
- def __enter__(self):
- return self
- def __exit__(self, type, value, traceback):
- pass
- def compress(self):
- with bz2.BZ2File(self.compressed_name, 'wb', compresslevel=9) as output:
- with open(self.uncompressed_name, 'rb') as input:
- shutil.copyfileobj(input, output)
- def uncompress(self):
- with bz2.BZ2File(self.compressed_name, 'rb', compresslevel=9) as input:
- with open(self.uncompressed_name, 'wb') as output:
- shutil.copyfileobj(input, output)
Add Comment
Please, Sign In to add comment