From: Lars Gustäbel Date: Tue, 13 Feb 2007 16:24:00 +0000 (+0000) Subject: Strip the '.gz' extension from the filename that is written to the X-Git-Tag: v2.6a1~2177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f19c1b5e0e753c85f6df8a2dec5f4bb75743fc10;p=python Strip the '.gz' extension from the filename that is written to the gzip header. --- diff --git a/Lib/gzip.py b/Lib/gzip.py index ea3656f81c..d85ba2b49f 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -149,15 +149,18 @@ class GzipFile: def _write_gzip_header(self): self.fileobj.write('\037\213') # magic header self.fileobj.write('\010') # compression method + fname = self.name + if fname.endswith(".gz"): + fname = fname[:-3] flags = 0 - if self.name: + if fname: flags = FNAME self.fileobj.write(chr(flags)) write32u(self.fileobj, long(time.time())) self.fileobj.write('\002') self.fileobj.write('\377') - if self.name: - self.fileobj.write(self.name + '\000') + if fname: + self.fileobj.write(fname + '\000') def _init_read(self): self.crc = zlib.crc32("")