A stream-based ZIP file extractor in Python, inspired by node-stream-zip.
Project description
py-stream-zip
py-stream-zip is a Python library for extracting ZIP files using a stream-based approach. It provides efficient access to ZIP file entries without needing to load the entire file into memory. This package is inspired by and gives credit to node-stream-zip.
Features
- Stream-based extraction of ZIP files.
- Reads the central directory and processes entries on the fly.
- Simple, synchronous API for ease of integration.
Installation
You can install py-stream-zip using pip:
pip install py-stream-zip
Usage
Below is an example demonstrating how to extract a file from a ZIP archive:
from py_stream_zip import StreamZip
zip_path = "path/to/archive.zip"
entry_name = "document.txt" # The name of the file inside the ZIP
# Create a StreamZip instance (ensuring entries are stored for random access)
zip_archive = StreamZip(zip_path, store_entries=True)
try:
# Extract and read the content of the specified entry.
data = zip_archive.entry_data_sync(entry_name)
print(data.decode("utf-8"))
# or save to file as binary
with open("document.txt", "wb") as f:
f.write(data)
except Exception as ex:
print(f"Error processing the ZIP file: {ex}")
finally:
# Always close the archive to free the file handle.
zip_archive.close()
For further reference, check out the provided test_unzip.py for a complete working example.
Credits
py-stream-zip is inspired by node-stream-zip. Special thanks to its developers for their contributions to the streaming ZIP extraction technique.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_stream_zip-0.1.0.tar.gz.
File metadata
- Download URL: py_stream_zip-0.1.0.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62c2c8e91365dcb5779e89a473787715a3d2cc740879f6fb800673e66a01f8f0
|
|
| MD5 |
55ec71ebb643ef06faf912d85999a395
|
|
| BLAKE2b-256 |
1ef489a2681a51a7365654eac50a240b0b4aaff55b041cd0854e9d3464e05a68
|
File details
Details for the file py_stream_zip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_stream_zip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df0f47ded93cd074c4b21aae2cb815c67f776064e25c0b607c1981b6ff4d20ce
|
|
| MD5 |
51834edbe36024b027f5de777177b09e
|
|
| BLAKE2b-256 |
ba970b237a164c2b1a2148d399db77278e0abfbe0e36d3a734cef7527f1b0b29
|