mirror of
https://github.com/python/cpython.git
synced 2025-11-30 14:59:12 +00:00
Strip the '.gz' extension from the filename that is written to the
gzip header.
This commit is contained in:
parent
5b1a785702
commit
f19c1b5e0e
1 changed files with 6 additions and 3 deletions
|
|
@ -149,15 +149,18 @@ class GzipFile:
|
||||||
def _write_gzip_header(self):
|
def _write_gzip_header(self):
|
||||||
self.fileobj.write('\037\213') # magic header
|
self.fileobj.write('\037\213') # magic header
|
||||||
self.fileobj.write('\010') # compression method
|
self.fileobj.write('\010') # compression method
|
||||||
|
fname = self.name
|
||||||
|
if fname.endswith(".gz"):
|
||||||
|
fname = fname[:-3]
|
||||||
flags = 0
|
flags = 0
|
||||||
if self.name:
|
if fname:
|
||||||
flags = FNAME
|
flags = FNAME
|
||||||
self.fileobj.write(chr(flags))
|
self.fileobj.write(chr(flags))
|
||||||
write32u(self.fileobj, long(time.time()))
|
write32u(self.fileobj, long(time.time()))
|
||||||
self.fileobj.write('\002')
|
self.fileobj.write('\002')
|
||||||
self.fileobj.write('\377')
|
self.fileobj.write('\377')
|
||||||
if self.name:
|
if fname:
|
||||||
self.fileobj.write(self.name + '\000')
|
self.fileobj.write(fname + '\000')
|
||||||
|
|
||||||
def _init_read(self):
|
def _init_read(self):
|
||||||
self.crc = zlib.crc32("")
|
self.crc = zlib.crc32("")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue