From ba5a449e2a07d6f4fe5c92806651ba176ecfa795 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Wed, 15 Jun 2016 09:53:48 +0200 Subject: [PATCH] added some more comments --- deltatar/tarfile.py | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 3845d68..f3c6425 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -580,8 +580,9 @@ class _Stream: the final file size if compression is being used because zlib/bz2 compressors do not allow inspection of their buffered data :-( - Still, we add 8 bytes for gz checksum, one encryption block size if - encryption is used and the size of our own buffer + Still, we add what close() would add: 8 bytes for gz checksum, one + encryption block size if encryption is used and the size of our own + buffer """ if self.closed: return self.bytes_written @@ -590,9 +591,9 @@ class _Stream: if self.buf: result += len(self.buf) if self.comptype == 'gz': - result += 8 # 2 longs = 8 byte + result += 8 # 2 longs = 8 byte (no extra info written for bzip2) if self.enctype == 'aes': - result += self.encryption.bs + result += self.encryption.bs # (salt was already written at start) return result def close(self, close_fileobj=True): @@ -2363,8 +2364,11 @@ class TarFile(object): def _size_left_file(self): """Calculates size left in a volume with a maximum volume size. + Assumes self.max_volume_size is set. + If using compression through a _Stream, use _size_left_stream instead """ + # left-over size = max_size - offset - 2 zero-blocks written in close size_left = self.max_volume_size - 2*BLOCKSIZE - self.offset # limit size left to a discrete number of blocks, because we won't # write only half a block when writting the end of a volume @@ -2372,6 +2376,12 @@ class TarFile(object): return BLOCKSIZE * (size_left // BLOCKSIZE) def _size_left_stream(self): + """ Calculates size left in a volume if using comression/encryption + + Assumes self.max_volume_size is set and self.fileobj is a _Stream + (otherwise use _size_left_file) + """ + # left-over size = max_size - bytes written - 2 zero-blocks (close) size_left = self.max_volume_size - self.fileobj.estim_file_size() \ - 2*BLOCKSIZE return BLOCKSIZE * (size_left // BLOCKSIZE) -- 1.7.1