Skip to main content

os.walk interface for nested zipfiles

Project description

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

pip install zipwalk

Usage

It has a similar interface to os.walk:

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 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:

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')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zipwalk-0.1.4.tar.gz (1.6 kB view hashes)

Uploaded Source

Built Distribution

zipwalk-0.1.4-py3-none-any.whl (1.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page