| 276 | return super().tell() |
| 277 | |
| 278 | def _write_gzip_header(self, compresslevel): |
| 279 | self.fileobj.write(b'\037\213') # magic header |
| 280 | self.fileobj.write(b'\010') # compression method |
| 281 | try: |
| 282 | # RFC 1952 requires the FNAME field to be Latin-1. Do not |
| 283 | # include filenames that cannot be represented that way. |
| 284 | fname = os.path.basename(self.name) |
| 285 | if not isinstance(fname, bytes): |
| 286 | fname = fname.encode('latin-1') |
| 287 | if fname.endswith(b'.gz'): |
| 288 | fname = fname[:-3] |
| 289 | except UnicodeEncodeError: |
| 290 | fname = b'' |
| 291 | flags = 0 |
| 292 | if fname: |
| 293 | flags = FNAME |
| 294 | self.fileobj.write(chr(flags).encode('latin-1')) |
| 295 | mtime = self._write_mtime |
| 296 | if mtime is None: |
| 297 | mtime = time.time() |
| 298 | write32u(self.fileobj, int(mtime)) |
| 299 | if compresslevel == _COMPRESS_LEVEL_BEST: |
| 300 | xfl = b'\002' |
| 301 | elif compresslevel == _COMPRESS_LEVEL_FAST: |
| 302 | xfl = b'\004' |
| 303 | else: |
| 304 | xfl = b'\000' |
| 305 | self.fileobj.write(xfl) |
| 306 | self.fileobj.write(b'\377') |
| 307 | if fname: |
| 308 | self.fileobj.write(fname + b'\000') |
| 309 | |
| 310 | def write(self,data): |
| 311 | self._check_not_closed() |