created a 2nd TarFile._size_left: one for file and one for stream
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Thu, 9 Jun 2016 15:56:00 +0000 (17:56 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 15 Jun 2016 11:18:02 +0000 (13:18 +0200)
deltatar/tarfile.py

index 50dd856..230b47e 100644 (file)
@@ -2358,7 +2358,7 @@ class TarFile(object):
         else:
             self.addfile(tarinfo)
 
-    def _size_left(self):
+    def _size_left_file(self):
         """Calculates size left in a volume with a maximum volume size.
         Assumes self.max_volume_size is set.
         """
@@ -2366,8 +2366,12 @@ class TarFile(object):
         # 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
         # and filling with zeros
-        blocks, remainder = divmod(size_left, BLOCKSIZE)
-        return blocks*BLOCKSIZE
+        return BLOCKSIZE * (size_left // BLOCKSIZE)
+
+    def _size_left_stream(self):
+        size_left = self.max_volume_size - self.fileobj.estim_file_size() \
+            - 2*BLOCKSIZE
+        return BLOCKSIZE * (size_left // BLOCKSIZE)
 
     def addfile(self, tarinfo, fileobj=None):
         """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is