self.__write(self.name + NUL)
+ def _finalize_write_gz (self):
+ if self.cmp is not None:
+ chunk = self.buf + self.cmp.flush()
+ if chunk:
+ if self.comptype == "gz":
+ # The native zlib crc is an unsigned 32-bit integer, but
+ # the Python wrapper implicitly casts that to a signed C
+ # long. So, on a 32-bit box self.crc may "look negative",
+ # while the same crc on a 64-bit box may "look positive".
+ # To avoid irksome warnings from the `struct` module, force
+ # it to look positive on all boxes.
+ chunk += struct.pack("<L", self.crc & 0xffffffff)
+ chunk += struct.pack("<L", self.concat_pos & 0xffffFFFF)
+ self.__enc_write (chunk)
+
+
def new_compression_block(self):
'''
Used to notify a new tar block is coming to create a new zip block
if self.closed:
return
- if self.mode == "w" and self.cmp is not None:
- self.buf += self.cmp.flush()
-
- if self.mode == "w" and self.buf:
- chunk = self.buf
+ if self.mode == "w":
+ self._finalize_write_gz ()
+ self.__enc_write(self.buf)
+ if self.enc is not None:
+ self._finalize_write_encrypt ()
self.buf = b""
- if self.comptype == "gz":
- # The native zlib crc is an unsigned 32-bit integer, but
- # the Python wrapper implicitly casts that to a signed C
- # long. So, on a 32-bit box self.crc may "look negative",
- # while the same crc on a 64-bit box may "look positive".
- # To avoid irksome warnings from the `struct` module, force
- # it to look positive on all boxes.
- chunk += struct.pack("<L", self.crc & 0xffffffff)
- chunk += struct.pack("<L", self.concat_pos & 0xffffFFFF)
- self.__enc_write(chunk)
- finalize_e = getattr (self, "_finalize_write_encrypt", None)
- finalize_c = getattr (self, "_finalize_write_gz" , None)
- if finalize_c is not None: finalize_c ()
- if finalize_e is not None: finalize_e ()
if close_fileobj and not self._extfileobj:
self.fileobj.close()