ruamel.std.zipfile
package ruamel.std.zipfile is a drop-in improvements over the standard zipfile package
You can just replace:
import zipfile
with:
import ruamel.std.zipfile as zipfile
The package includes InMemoryZipFile, which allows easy creation of ZIP files in memory, and allows for streaming or writing out to disc after full creation:
with InMemoryZipFile() as imz:
imz.append("test.txt", "Another test").append("test2.txt", "Still another")
with open('some_file.zip', 'wb') as fp:
fp.write(imz.data)
which will write a two file ZIP file, the first file of which is named test.txt with content Another test. The .data content can also be dynamically returned to a web browser, etc.
File deletion from ZIP
Taking advantage of the delayed writing of InMemoryZipFile, the function delete_from_zip_file(file_name, pattern, file_names), takes a string or pathlib.Path as file_name.
Any files matching the pattern, if provided, are deleted from the file, as well as are any files matching file_names (a list of string/Path, single non-list instances are allowed).
The following deletes any files ending in .pth and the file tmp/README.rst from a ZIP file test.zip:
delete_from_zip_file('test.zip', pattern='.*.pth', file_names=['README.rst'])
or:
delete_from_zip_file('test.zip', pattern='.*.pth', file_names='README.rst')
or:
delete_from_zip_file('test.zip', pattern=re.compile('.*.pth'), file_names='README.rst')
Please note that this a ``re`` pattern not a ``glob`` pattern. You can, but don’t have to provide a pattern compiled with re.compile()
The ZIP file is recreated and recompressed, take this into account when deleting files (restrict the size of files you handle, combine patterns instead of doing multiple calls).
Metadata
Release files for ruamel.std.zipfile 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ruamel.std.zipfile-0.1.0.tar.gz | 11.3 kB | Without provenance | Details for ruamel.std.zipfile-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ruamel.std.zipfile-0.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for ruamel.std.zipfile-0.1.0-py2.py3-none-any.whl |
Total release size: 17.8 kB
Release files / ruamel.std.zipfile-0.1.0.tar.gz
| Download URL | ruamel.std.zipfile-0.1.0.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d7cc5ffdb24897670305d616ff2d864dbfc00c55b9b37dec2d08d046c76d1a30
|
|
BLAKE2b-256 checksum How to use checksums |
bdadf954e535b2ae686277be56a3164c4eb55743c469ad81750b0769a5718bb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / ruamel.std.zipfile-0.1.0-py2.py3-none-any.whl
| Download URL | ruamel.std.zipfile-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
797e000fef6da0f25005d9c666ca8564ec70b8bf8521ddf51ff4cca8c8b35b36
|
|
BLAKE2b-256 checksum How to use checksums |
27167ed3633177023d6d186b9731128fa320d739f29defe47371db00ee1c75f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ruamel.std.zipfile 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.