Flush bz2 data even if nothing had been written so far. Fixes #1013882.
Will backport to 2.3.
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index ff9f51f..2d5bf64 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -350,9 +350,9 @@
         if self.closed:
             return
 
+        if self.mode == "w" and self.type != "tar":
+            self.buf += self.cmp.flush()
         if self.mode == "w" and self.buf:
-            if self.type != "tar":
-                self.buf += self.cmp.flush()
             self.fileobj.write(self.buf)
             self.buf = ""
             if self.type == "gz":