The old implementation always initialized in the ctor regardless
of whether contents would be written to the archive. For empty
archives this now has to be done in ``.close()`` if no data has
been added yet.
def close(self):
"""Close the TarFile. In write-mode, two finishing zero blocks are
- appended to the archive.
+ appended to the archive. A special case are empty archives which are
+ initialized accordingly so the two mandatory blocks of zeros are
+ written abiding by the requested encryption and compression settings.
"""
if self.closed:
return
if self.mode in "aw":
+ if self.arcmode & ARCMODE_CONCAT and self.fileobj.tell () == 0:
+ self.fileobj.next ("")
self.fileobj.write(NUL * (BLOCKSIZE * 2))
self.offset += (BLOCKSIZE * 2)
# fill up the end with zero-blocks