I think you should use Python's ```gzip``` module for this.