From 57db1546a96784dd38eb92dc9e22c4160fa635d8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Mon, 27 Mar 2017 14:10:51 +0200 Subject: [PATCH] unify zlib initialization --- deltatar/tarfile.py | 40 +++++++++++++++++++++------------------- 1 files changed, 21 insertions(+), 19 deletions(-) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 9708f97..e4b6910 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -610,6 +610,22 @@ class _Stream: 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("