Initialize for writing with gzip compression.
(self, compresslevel)
| 422 | self.close() |
| 423 | |
| 424 | def _init_write_gz(self, compresslevel): |
| 425 | """Initialize for writing with gzip compression. |
| 426 | """ |
| 427 | self.cmp = self.zlib.compressobj(compresslevel, |
| 428 | self.zlib.DEFLATED, |
| 429 | -self.zlib.MAX_WBITS, |
| 430 | self.zlib.DEF_MEM_LEVEL, |
| 431 | 0) |
| 432 | timestamp = struct.pack("<L", int(time.time())) |
| 433 | self.__write(b"\037\213\010\010" + timestamp + b"\002\377") |
| 434 | if self.name.endswith(".gz"): |
| 435 | self.name = self.name[:-3] |
| 436 | # Honor "directory components removed" from RFC1952 |
| 437 | self.name = os.path.basename(self.name) |
| 438 | # RFC1952 says we must use ISO-8859-1 for the FNAME field. |
| 439 | self.__write(self.name.encode("iso-8859-1", "replace") + NUL) |
| 440 | |
| 441 | def write(self, s): |
| 442 | """Write string s to the stream. |