Patch #1652681: create nonexistent files in append mode and
allow appending to empty files.
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 47bd9a7..54bb1b8 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1060,6 +1060,10 @@
         self.mode = {"r": "rb", "a": "r+b", "w": "wb"}[mode]
 
         if not fileobj:
+            if self._mode == "a" and not os.path.exists(self.name):
+                # Create nonexistent files in append mode.
+                self._mode = "w"
+                self.mode = "wb"
             fileobj = file(self.name, self.mode)
             self._extfileobj = False
         else:
@@ -1093,7 +1097,8 @@
                     self.fileobj.seek(0)
                     break
                 if tarinfo is None:
-                    self.fileobj.seek(- BLOCKSIZE, 1)
+                    if self.offset > 0:
+                        self.fileobj.seek(- BLOCKSIZE, 1)
                     break
 
         if self._mode in "aw":
@@ -1120,7 +1125,7 @@
            'r:'         open for reading exclusively uncompressed
            'r:gz'       open for reading with gzip compression
            'r:bz2'      open for reading with bzip2 compression
-           'a' or 'a:'  open for appending
+           'a' or 'a:'  open for appending, creating the file if necessary
            'w' or 'w:'  open for writing without compression
            'w:gz'       open for writing with gzip compression
            'w:bz2'      open for writing with bzip2 compression