buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.fileobj.write(buf)
self.offset += len(buf)
+ self._dbg(1, 'tarinfo has size {}'.format(len(buf)))
if self.max_volume_size:
if isinstance(self.fileobj, _Stream):
size_can_write = min(target_size_left, source_size_left)
while size_can_write > 0:
+ self._dbg(1, 'source_size_left={}, size_left={} --> write {}'
+ .format(source_size_left, target_size_left,
+ size_can_write))
copyfileobj(fileobj, self.fileobj, size_can_write)
self.offset += size_can_write
source_size_left -= size_can_write
size_can_write = min(target_size_left, source_size_left)
# now target_size_left == 0 or source_size_left == 0
+ self._dbg(1, 'source_size_left={}, size_left={} --> end write loop'
+ .format(source_size_left, target_size_left))
# if there is data left to write, we need to create a new volume
if source_size_left > 0:
# write new volume header
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
+ self._dbg(1, 'tarinfo has size {}'.format(len(buf)))
self.fileobj.write(buf)
self.offset += len(buf)
# --> _size_left should be big again
target_size_left = _size_left()
size_can_write = min(target_size_left, source_size_left)
+ self._dbg(1, 'new volume')
# now, all data has been written. We may have to fill up the rest of
# the block in target with 0s
remainder = (tarinfo.size - tarinfo.volume_offset) % BLOCKSIZE
+ self._dbg(1, 'wrote everything, fill with {} 0s to {}'
+ .format(BLOCKSIZE - remainder, BLOCKSIZE))
if remainder > 0:
self.fileobj.write(NUL * (BLOCKSIZE - remainder))
self.offset += BLOCKSIZE - remainder
self._extfileobj = False
if isinstance(self.fileobj, _Stream):
+ self._dbg(1, 'open_volume: create a _Stream')
fileobj = _Stream(name=name,
mode=self.fileobj.mode,
comptype=self.fileobj.comptype,
concat_stream=self.fileobj.concat_stream)
else:
# here, we lose information about compression/encryption!
+ self._dbg(1, 'open_volume: builtin open')
fileobj = bltn_open(name, self._mode)
else:
if name is None and hasattr(fileobj, "name"):
if hasattr(fileobj, "mode"):
self._mode = fileobj.mode
self._extfileobj = True
+ self._dbg(1, 'open_volume: using external fileobj {}'
+ .format(fileobj))
self.name = os.path.abspath(name) if name else None
self.fileobj = fileobj