Guest User

Untitled

a guest
Dec 7th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import bz2
  2. import shutil
  3.  
  4. class Compander(object):
  5.  
  6. def __init__(self, uncompressed_name, compressed_name):
  7. self.uncompressed_name = uncompressed_name
  8. self.compressed_name = compressed_name
  9.  
  10. def __enter__(self):
  11. return self
  12.  
  13. def __exit__(self, type, value, traceback):
  14. pass
  15.  
  16. def compress(self):
  17. with bz2.BZ2File(self.compressed_name, 'wb', compresslevel=9) as output:
  18. with open(self.uncompressed_name, 'rb') as input:
  19. shutil.copyfileobj(input, output)
  20.  
  21. def uncompress(self):
  22. with bz2.BZ2File(self.compressed_name, 'rb', compresslevel=9) as input:
  23. with open(self.uncompressed_name, 'wb') as output:
  24. shutil.copyfileobj(input, output)
Add Comment
Please, Sign In to add comment