Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. import zlib
  2. from sys import argv
  3.  
  4.  
  5. def decode(s):
  6. dec = zlib.decompress(s)
  7. res = dec.decode("utf-8")
  8. return res
  9.  
  10.  
  11. def encode(s):
  12. enc = zlib.compress(s)
  13. return enc
  14.  
  15.  
  16. if __name__ == "__main__":
  17.  
  18. with open(argv[1], "rb") as fi:
  19. s = fi.read()
  20.  
  21. if argv[1][-4:] == ".xml":
  22. out = encode(s)
  23.  
  24. with open(argv[1][:-4], "wb") as fo:
  25. fo.write(out)
  26.  
  27. else:
  28. out = decode(s)
  29.  
  30. with open(argv[1] + ".xml", "w", encoding="utf-8") as fo:
  31. fo.write(out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement