This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add data_offset field to ZipInfo
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ammar2, zhangxp1998
Priority: normal Keywords: patch

Created on 2021-08-26 02:30 by zhangxp1998, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 27961 open zhangxp1998, 2021-08-26 02:32
Messages (2)
msg400306 - (view) Author: Kelvin Zhang (zhangxp1998) * Date: 2021-08-26 02:30
Currently python's zipfile module does not have a way query starting offset of compressed data. This might be handy when the user wants to copy compressed data as is. Therefore I propose adding a data_offset field to zipfile.ZipInfo, which stores the offset to beginning of compressed data.
msg403316 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2021-10-06 15:22
Could you explain your use-case for this feature in a bit more detail? zipfile is meant to be a relatively high level library to do common tasks such as reading/writing/listing files.

The use case for `data_offset` proposed here seems to be relatively advanced and I don't see how it would be to useful for the vast majority of users.


(Without adding to the public API, I think you can achieve a pretty similar functionality by using the following)

compressed_data = zipfile.open(zipinfo)._read2(compressed_size)

Obviously, this relies on undocumented internals, but for a niche use case that might not be the worst thing: https://github.com/python/cpython/blob/61892c04764e1f3a659bbd09e6373687a27d36e2/Lib/zipfile.py#L1042-L1056
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89169
2021-10-06 15:22:47ammar2setnosy: + ammar2
messages: + msg403316
2021-08-26 02:32:09zhangxp1998setkeywords: + patch
stage: patch review
pull_requests: + pull_request26408
2021-08-26 02:30:22zhangxp1998create