Skip to content

gh-146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size#146424

Open
dhanusharer wants to merge 1 commit intopython:mainfrom
dhanusharer:improve-tarfile-docs
Open

gh-146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size#146424
dhanusharer wants to merge 1 commit intopython:mainfrom
dhanusharer:improve-tarfile-docs

Conversation

@dhanusharer
Copy link

@dhanusharer dhanusharer commented Mar 25, 2026

Closes #146396

Summary

Improve the tarfile documentation by clarifying the meaning of TarInfo.size and adding a practical example for reading file contents directly into memory.

Changes

  • Clarified that TarInfo.size refers to the size of the archived file’s data (excluding header information)
  • Added an example demonstrating how to use TarFile.extractfile() to read file contents without extracting to disk

Motivation

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.

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news labels Mar 25, 2026
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 25, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Mar 25, 2026
@dhanusharer dhanusharer changed the title gh-146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size #146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size Mar 25, 2026
@dhanusharer dhanusharer changed the title #146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size gh-146396: Improve tarfile docs with extractfile() example and clarify TarInfo.size Mar 25, 2026
@yngvem
Copy link
Contributor

yngvem commented Mar 25, 2026

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 tarfile.open compared to the five that explicitly use open and close. Would this be a nice time to harmonise the tarfile docs and just use the context manager everywhere?

@dhanusharer
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Unclear documentation for TarFile

2 participants