# Advance the file pointer.
if self.offset != self.fileobj.tell():
+ if self.offset == 0:
+ return None
self.fileobj.seek(self.offset - 1)
if not self.fileobj.read(1):
raise ReadError("unexpected end of data")
with self.assertRaises(tarfile.ReadError):
tarfile.open(self.tarname)
+ def test_next_on_empty_tarfile(self):
+ fd = io.BytesIO()
+ tf = tarfile.open(fileobj=fd, mode="w")
+ tf.close()
+
+ fd.seek(0)
+ with tarfile.open(fileobj=fd, mode="r|") as tf:
+ self.assertEqual(tf.next(), None)
+
+ fd.seek(0)
+ with tarfile.open(fileobj=fd, mode="r") as tf:
+ self.assertEqual(tf.next(), None)
class MiscReadTest(MiscReadTestBase, unittest.TestCase):
test_fail_comp = None