compress.py 490 B

123456789101112131415161718192021
  1. #!/usr/bin/env python -u
  2. # simple script that takes data on stdin and outputs bz2 compressed data
  3. # just to avoid having to install bzip2.exe on windows platforms
  4. import bz2, os, sys
  5. bufsize=4096
  6. if __name__ == "__main__":
  7. compress = bz2.BZ2Compressor()
  8. data = sys.stdin.read(bufsize)
  9. while data:
  10. cdata = compress.compress(data)
  11. if cdata:
  12. sys.stdout.write(cdata)
  13. data = sys.stdin.read(bufsize)
  14. cdata = compress.flush()
  15. if cdata:
  16. sys.stdout.write(cdata)