gh-146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size#146424
gh-146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size#146424dhanusharer wants to merge 1 commit intopython:mainfrom
Conversation
…s and clarify TarInfo.size
|
This is pretty much exactly what I thought was needed when I created #146396! I just had one thought: This newest example is now a third example that uses a context manager with |
|
Thanks for the suggestion! Using a context manager does improve readability and ensures proper resource handling. I agree that harmonizing the examples across the tarfile documentation would be beneficial. However, since this PR is focused on clarifying TarInfo.size and adding an example for extractfile(), it might be better to handle a broader consistency update in a separate PR. Happy to help with that as a follow-up if needed! |
Closes #146396
Summary
Improve the tarfile documentation by clarifying the meaning of
TarInfo.sizeand adding a practical example for reading file contents directly into memory.Changes
TarInfo.sizerefers to the size of the archived file’s data (excluding header information)TarFile.extractfile()to read file contents without extracting to diskMotivation
The current documentation does not clearly explain how to read file data from a tar archive in memory. This change improves usability and helps developers discover the intended high-level API without relying on internal details.