gh-84481: Add ZipFile.data_offset attribute#132165
Conversation
This attribute provides the offset to zip data from the start of the file, when available.
|
I have signed the CLA with my current email. (I had already signed it under another email anyway) |
| self.fp = _Tellable(self.fp) | ||
| self.start_dir = 0 | ||
| self._seekable = False | ||
| self._data_offset = None |
There was a problem hiding this comment.
It may not be set if mode == 'a' and if BadZipFile is raised. In this case, we should still have a None according to the docs (otherwise an AttributeError will be raised).
For mode 'r', it should be noted that failing _RealGetContents() means that the object will never be initialized so we don't care about the lack of attribute.
There was a problem hiding this comment.
I believe that in this case, since mode 'a' calls tell() unconditionally, we can set the data_offset to the result of that, right?
There was a problem hiding this comment.
Though honestly the defensive thing to do here is to initialize it to None early on then change it later when possible.
There was a problem hiding this comment.
Though honestly the defensive thing to do here is to initialize it to None early on then change it later when possible.
Yes, that's what I thought.
)" This reverts commit 0788948.
* Revert "pythongh-84481: Make ZipFile.data_offset more robust (pythonGH-132178)" This reverts commit 6cd1d6c. * Revert "pythongh-84481: Add ZipFile.data_offset attribute (pythonGH-132165)" This reverts commit 0788948. --------- (cherry picked from commit 6bf1c0a) Co-authored-by: Emma Smith <emma@emmatyping.dev> Co-authored-by: Gregory P. Smith <greg@krypto.org>
…36955) gh-136170: Revert adding `ZipFile.data_offset` (GH-136950) * Revert "gh-84481: Make ZipFile.data_offset more robust (GH-132178)" This reverts commit 6cd1d6c. * Revert "gh-84481: Add ZipFile.data_offset attribute (GH-132165)" This reverts commit 0788948. --------- (cherry picked from commit 6bf1c0a) Co-authored-by: Emma Smith <emma@emmatyping.dev> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* Revert "pythongh-84481: Make ZipFile.data_offset more robust (python#132178)" This reverts commit 6cd1d6c. * Revert "pythongh-84481: Add ZipFile.data_offset attribute (python#132165)" This reverts commit 0788948. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
* Revert "pythongh-84481: Make ZipFile.data_offset more robust (python#132178)" This reverts commit 6cd1d6c. * Revert "pythongh-84481: Add ZipFile.data_offset attribute (python#132165)" This reverts commit 0788948. --------- Co-authored-by: Gregory P. Smith <greg@krypto.org>
…-136950) (python#136955) pythongh-136170: Revert adding `ZipFile.data_offset` (pythonGH-136950) * Revert "pythongh-84481: Make ZipFile.data_offset more robust (pythonGH-132178)" This reverts commit 6cd1d6c. * Revert "pythongh-84481: Add ZipFile.data_offset attribute (pythonGH-132165)" This reverts commit 0788948. --------- (cherry picked from commit 6bf1c0a) Co-authored-by: Emma Smith <emma@emmatyping.dev> Co-authored-by: Gregory P. Smith <greg@krypto.org>
This attribute provides the offset to zip data from the start of the file, when available.
I chose
data_offsetto avoid confusion with the_offsetproperty that is unrelated.📚 Documentation preview 📚: https://cpython-previews--132165.org.readthedocs.build/