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
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):
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
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)