Unclear documentation for TarFile
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Documentation
The tarfile docs does not make it clear how a programmer can read data from a tarfile into memory without doing a round-trip writing it to the file system. As far as I understand, reading partial data from a tar file essentially amounts to the following steps:
import tarfile
with open("myfile.tar") as f:
tar = tarfile.TarFile(fileobj=f)
tar_info = next(member for member in f.getmembers() if member.is_file())
f.seek(tar_info.offset_data)
data = f.read(tar_info.size)
However, to arrive at this, you either need to be confident enough to read the CPython source code, or you need to know that tar-files stores the byte-contents unchanged, and that TarInfo.size is the size of the data without the file header. Neither of these are obvious for less experienced programmers.
I suggest that we make two changes to the tarfile docs:
- Expand the documentation for
TarInfo.sizeso it says more than just "Size in bytes". Size of what exactly? The archived file as far as I can tell. - Include a minimal example (like I have above, but slightly more pedagogical maybe) to the Reading Examples section.
I can propose a PR with these changes if you think that is useful.
Linked PRs
- gh-146424
- gh-151909
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelas seções da documentação de tarfile sobre TarInfo.size e Reading Examples, que o issue identifica como necessitando de alterações. O trabalho estará concluído quando a descrição de size explicar o que é medido e os exemplos de leitura incluírem um exemplo mínimo e didático em memória; verifique os PRs vinculados antes de começar.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- documentation
- Tipo de issue
- Documentação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 35/100