allenai / allenai/cached_path

Caching a single file in a tar/zip should not extract all files

Đang mở
#260 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Feature request
Ngôn ngữ chính
Python
Star
47
Fork
22
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

**Is your feature request related to a problem? Please describe.**
When extracting a single file from a tar/zip archive, currently all files in the archive are extracted using the `tarfile.extractall` function even though only a single file was requested. This leads to bloated cache directories containing unnecessary files. Note below, I only request `dummy.txt` but I also get `folder`:

```python
>>> import cached_path
>>> path = "https://github.com/allenai/cached_path/raw/refs/heads/main/test_fixtures/utf-8_sample/archives/utf-8.tar.gz!dummy.txt"
>>> f = cached_path.cached_path(path, extract_archive=True, quiet=True)
>>> [x.name for x in f.parent.iterdir()]
['dummy.txt', 'folder']
```

**Describe the solution you'd like**
Extract only the file requested using the `tarfile.extract` function rather than the `tarfile.extractall` function.

**Describe alternatives you've considered**
None

**Additional context**
None

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.