decompress_log.py 899 B

123456789101112131415161718192021222324252627282930313233
  1. import zlib
  2. import os
  3. import sys
  4. def decompress_py2(args):
  5. decompressor = zlib.decompressobj(-zlib.MAX_WBITS)
  6. src = args[0]
  7. dst = src[:len(src) - 4] + "-decompress.zap"
  8. _buffer = []
  9. with open(src, "rb") as src_fp:
  10. _buffer = bytearray(os.path.getsize(src))
  11. src_fp.readinto(_buffer)
  12. with open(dst, "w+") as dst_fp:
  13. tmp = decompressor.decompress(str(_buffer))
  14. dst_fp.write(tmp)
  15. def decompress_py3(args):
  16. decompressor = zlib.decompressobj(-zlib.MAX_WBITS)
  17. src = args[0]
  18. dst = src[:len(src) - 4] + "-decompress.zap"
  19. with open(src, "rb") as src_fp:
  20. _buffer = src_fp.read()
  21. with open(dst, "w+") as dst_fp:
  22. tmp = decompressor.decompress(_buffer)
  23. dst_fp.write(bytes.decode(tmp))
  24. if __name__ == "__main__":
  25. decompress_py3(sys.argv[1:])
  26. # py2用下面的方法
  27. # decompress_py2(sys.argv[1:])