Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python
- import base64
- import zlib
- import sys
- """
- name: data_compressor.py
- description: Lossless data compression code snippet with the help of zlib DEFLATE (Lempel–Ziv 1977) compression algorithm.
- author: Bryan Angelo Pedrosa
- """
- class data_compress:
- def __init__(self,location):
- self.location = location
- def mainsys(self):
- with open(self.location,"rb") as f:
- filedata = zlib.compress(base64.b64encode(f.read()))#read a file; encode with base64; compress (add a buffer if needed)
- return filedata
- class data_decompress:
- def __init__(self,location):
- self.location = location
- def mainsys(self):
- with open(self.location,"rb") as f:
- filedata = zlib.decompress(base64.b64encode(f.read()))#read a file; encode with base64; decompress (add a buffer if needed)
- return filedata
- if __name__ == "__main__":
- if len(sys.argv) == 3:
- if sys.argv[1] == "compress":
- print(data_compress(sys.argv[2]).mainsys())
- elif sys.argv[1] == "decompress":
- print(data_decompress(sys.argv[2]).mainsys())
- else:
- print("argument must be 3, but you entered %s" % len(sys.argvprogram
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement