https://github.com/meyer1994/zipwalk
An os.walk interface for nested zip files
https://github.com/meyer1994/zipwalk
python zip
Last synced: 19 days ago
JSON representation
An os.walk interface for nested zip files
- Host: GitHub
- URL: https://github.com/meyer1994/zipwalk
- Owner: meyer1994
- License: mit
- Created: 2023-05-03T20:22:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-16T00:24:37.000Z (over 2 years ago)
- Last Synced: 2024-01-16T05:31:46.345Z (over 2 years ago)
- Topics: python, zip
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# zipwalk
A very simple walker that recursively walks through nested zipfiles
## About
This project was created because I needed a way to iterate over nested zipfiles
without unzipping them.
## Install
```sh
pip install zipwalk
```
## Usage
It has a similar interface to `os.walk`:
```py
from zipwalk import zipwalk
for root, zips, files in zipwalk('tests/1.zip'):
print('root:', root.filename)
print('zips:', zips)
print('files:', files)
# output:
# root: tests/1.zip
# zips: {'2.zip'}
# files: {'1c.txt', 'dir/d1.txt', '1b.txt', '1a.txt'}
# root: 2.zip
# zips: set()
# files: {'2c.txt', '2b.txt', '2a.txt'}
```
`root` is an [ZipFile][1] instance opened on read mode, `r`. All zip files are
opened using `with` context manager and will be closed once the generator is
exhausted.
You can use the zip walker like the following:
```py
from pathlib import Path
from zipfile import ZipFile
from zipwalk import zipwalk
zipwalk(ZipFile('tests/1.zip'))
zipwalk(Path('tests/1.zip'))
zipwalk('tests/1.zip')
```
[1]: https://docs.python.org/3/library/zipfile.html