remainder = -1 # track size in encrypted entries
def __init__(self, name, mode, comptype, fileobj, bufsize,
- concat_stream=False, encryption=None, compresslevel=9,
- noinit=False):
+ concat_stream=False, encryption=None, compresslevel=9):
"""Construct a _Stream object.
"""
self._extfileobj = True
if concat_stream is True:
self._init_read_gz()
elif mode == "w":
- if noinit is False:
- self._new_gz_block()
+ if self.encryption is None and concat_stream is False:
+ self._init_write_gz ()
self.crc = zlib.crc32(b"") & 0xFFFFffff
elif comptype == "bz2":
self.buf = b""
- def new_compression_block(self):
- '''
- Used to notify a new tar block is coming to create a new zip block
- '''
- if self.mode != "w":
- raise CompressionError("new compression blocks can only be added in mode 'w'")
- if self.comptype == "gz":
- self._new_gz_block(True)
- elif self.encryption is not None:
- pass
- else:
- raise CompressionError("Concat compression only available for comptype 'gz'")
-
- def _new_gz_block(self, set_last_block_offset=False):
+ def _init_write_gz (self, set_last_block_offset=False):
'''
Add a new gzip block, closing last one
'''
- self.close(close_fileobj=False)
- self.closed = False
self.concat_pos = 0
self.crc = self.zlib.crc32(b"") & 0xFFFFffff
first = False
0)
# if aes, we encrypt after compression
- if self.encryption is not None:
- pass
- elif set_last_block_offset:
+ if self.encryption is None and set_last_block_offset:
self.last_block_offset = self.fileobj.tell()
self.__write(gz_header (self.name if first is True else None))
if self.closed:
return
- if self.mode == "w":
- self._finalize_write_gz ()
- self.__enc_write(self.buf)
-
if close_fileobj is True:
+
if self.mode == "w":
+ if self.cmp is not None:
+ self._finalize_write_gz ()
# end of Tar archive marker (two empty blocks) was written
self._finalize_write_encrypt ()
if not self._extfileobj:
tarinfo = copy.copy(tarinfo)
+ if self.concat_compression is True:
+ self.fileobj._finalize_write_gz ()
+
if getattr (self.fileobj, "encryption", None) is not None:
self.fileobj._finalize_write_encrypt ()
self.fileobj._init_write_encrypt (tarinfo.name)
if self.concat_compression:
- self.fileobj.new_compression_block()
+ self.fileobj._init_write_gz (True)
self.last_block_offset = self.fileobj.last_block_offset
else:
self.last_block_offset = self.fileobj.tell()
# Only finalize the crypto entry here if we’re continuing with
# another one; otherwise, the encryption must include the block
# padding below.
- if getattr (self.fileobj, "encryption", None) is not None:
- self.fileobj.close (close_fileobj=True)
-
tarinfo.type = GNUTYPE_MULTIVOL
if not self.new_volume_handler or\
tarinfo.volume_offset = tarinfo.size - source_size_left
self.volume_tarinfo = tarinfo
+ # the “new_volume_handler” is supposed to call .close() on the
+ # “fileobj” _Stream
self.new_volume_handler(self, self.base_name, self.volume_number)
+ if getattr (self.fileobj, "cmp", None) is not None:
+ # e. g. compressed PAX header written
+ self.fileobj._finalize_write_gz ()
self.volume_tarinfo = None
if getattr (self.fileobj, "encryption", None) is not None:
self.fileobj._init_write_encrypt (tarinfo.name)
- if self.concat_compression:
- self.fileobj.new_compression_block()
+ if getattr (self.fileobj, "cmp", None) is not None:
+ self.fileobj._init_write_gz ()
# write new volume header
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.pax_headers.update(volume_info)
+ if isinstance(self.fileobj, _Stream):
+ self.fileobj._init_write_gz ()
buf = self.tarinfo.create_pax_global_header(volume_info.copy())
self.fileobj.write(buf)
self.offset += len(buf)