if self.mode == "w":
self._finalize_write_gz ()
self.__enc_write(self.buf)
- if self.encryption is not None:
- self._finalize_write_encrypt ()
+ self._finalize_write_encrypt ()
if close_fileobj and not self._extfileobj:
self.fileobj.close()
You can create TarInfo objects using gettarinfo().
On Windows platforms, `fileobj' should always be opened with mode
'rb' to avoid irritation about the file size.
+
+ Encryption restarts with each volume. Compression restarts with each
+ file and may span volumes.
"""
self._check("aw")
tarinfo = copy.copy(tarinfo)
+
+ self.fileobj._finalize_write_encrypt ()
+ self.fileobj._init_write_encrypt (tarinfo.name)
+
if self.concat_compression:
self.fileobj.new_compression_block()
self.last_block_offset = self.fileobj.last_block_offset
else:
self.last_block_offset = self.fileobj.tell()
- # below attributes aren’t present with other compression methods
- init_e = getattr (self.fileobj, "_init_write_encrypt", None)
- finalize_e = getattr (self.fileobj, "_finalize_write_encrypt", None)
-
- def new_item_hook (): # crypto is outer, compress is inner
- if init_e is not None: init_e (tarinfo.name)
-
- def end_item_hook (): # crypto is outer, compress is inner
- if finalize_e is not None: finalize_e ()
-
- end_item_hook () # finalize current object
- new_item_hook ()
-
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.fileobj.write(buf)
self.offset += len(buf)
# If there's no data to follow, finish
if not fileobj:
- new_item_hook ()
if self.save_to_members:
self.members.append(tarinfo)
return
# Only finalize the crypto entry here if we’re continuing with
# another one; otherwise, the encryption must include the block
# padding below.
- end_item_hook ()
+ self.fileobj._finalize_write_encrypt ()
tarinfo.type = GNUTYPE_MULTIVOL
self.volume_tarinfo = None
- new_item_hook ()
+ self.fileobj._init_write_encrypt (tarinfo.name)
# write new volume header
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)