-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-84481: Add ZipFile.data_offset attribute #132165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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) |
except (AttributeError, OSError): | ||
self.fp = _Tellable(self.fp) | ||
self.start_dir = 0 | ||
self._seekable = False | ||
self._data_offset = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
* Add ZipFile.data_offset attribute This attribute provides the offset to zip data from the start of the file, when available. * Add blurb-it * Try fixing class ref in NEWS
This attribute provides the offset to zip data from the start of the file, when available.
I chose
data_offset
to avoid confusion with the_offset
property that is unrelated.📚 Documentation preview 📚: https://cpython-previews--132165.org.readthedocs.build/