added some more comments
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 15 Jun 2016 07:53:48 +0000 (09:53 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 15 Jun 2016 11:18:03 +0000 (13:18 +0200)
deltatar/tarfile.py

index 3845d68..f3c6425 100644 (file)
@@ -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)