with zipfile.ZipFile(fp, "w") as zipfp:
self.assertEqual(zipfp.data_offset, 16)
+ def test_data_offset_append_with_bad_zip(self):
+ with io.BytesIO() as fp:
+ fp.write(b"this is a prefix")
+ with zipfile.ZipFile(fp, "a") as zipfp:
+ self.assertEqual(zipfp.data_offset, 16)
+
def test_data_offset_write_no_tell(self):
# The initializer in ZipFile checks if tell raises AttributeError or
# OSError when creating a file in write mode when deducing the offset
raise OSError("Unimplemented!")
with NoTellBytesIO() as fp:
with zipfile.ZipFile(fp, "w") as zipfp:
- self.assertIs(zipfp.data_offset, None)
+ self.assertIsNone(zipfp.data_offset)
class EncodedMetadataTests(unittest.TestCase):
self._lock = threading.RLock()
self._seekable = True
self._writing = False
+ self._data_offset = None
try:
if mode == 'r':
self.fp = _Tellable(self.fp)
self.start_dir = 0
self._seekable = False
- self._data_offset = None
else:
# Some file-like objects can provide tell() but not seek()
try:
# even if no files are added to the archive
self._didModify = True
self.start_dir = self.fp.tell()
+ self._data_offset = self.start_dir
else:
raise ValueError("Mode must be 'r', 'w', 'x', or 'a'")
except: