ruamel.std.zipfile
==================
`package ruamel.std.zipfile <https://bitbucket.org/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).
Raw data
{
"_id": null,
"home_page": "https://bitbucket.org/ruamel/std.zipfile",
"name": "ruamel.std.zipfile",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Anthon van der Neut",
"author_email": "a.van.der.neut@ruamel.eu",
"download_url": "https://files.pythonhosted.org/packages/bd/ad/f954e535b2ae686277be56a3164c4eb55743c469ad81750b0769a5718bb1/ruamel.std.zipfile-0.1.0.tar.gz",
"platform": "",
"description": "ruamel.std.zipfile\n==================\n\n`package ruamel.std.zipfile <https://bitbucket.org/ruamel/std.zipfile>`_ is a drop-in\nimprovements over the standard zipfile package\n\nYou can just replace::\n\n import zipfile\n\nwith::\n\n import ruamel.std.zipfile as zipfile\n\n\nThe package includes InMemoryZipFile, which allows easy creation of ZIP files in memory,\nand allows for streaming or writing out to disc after full creation::\n\n with InMemoryZipFile() as imz:\n imz.append(\"test.txt\", \"Another test\").append(\"test2.txt\", \"Still another\")\n with open('some_file.zip', 'wb') as fp:\n fp.write(imz.data)\n\nwhich will write a two file ZIP file, the first file of which is named\n``test.txt`` with content ``Another test``. The ``.data`` content can\nalso be dynamically returned to a web browser, etc.\n\n\nFile deletion from ZIP\n----------------------\n\nTaking advantage of the delayed writing of ``InMemoryZipFile``, the\nfunction ``delete_from_zip_file(file_name, pattern, file_names)``,\ntakes a ``string`` or ``pathlib.Path`` as file_name.\n\nAny files matching the pattern, if provided, are deleted from the\nfile, as well as are any files matching ``file_names`` (a list of\nstring/Path, single non-list instances are allowed).\n\nThe following deletes any files ending in `.pth` and the file\n`tmp/README.rst` from a ZIP file ``test.zip``::\n\n delete_from_zip_file('test.zip', pattern='.*.pth', file_names=['README.rst'])\n\nor::\n\n delete_from_zip_file('test.zip', pattern='.*.pth', file_names='README.rst')\n\nor::\n\n delete_from_zip_file('test.zip', pattern=re.compile('.*.pth'), file_names='README.rst')\n\n\n*Please note that this a ``re`` pattern not a ``glob`` pattern.*\nYou can, but don't have to provide a pattern compiled with\n``re.compile()``\n\n\nThe ZIP file is recreated and recompressed, take this into account\nwhen deleting files (restrict the size of files you handle, combine\npatterns instead of doing multiple calls).",
"bugtrack_url": null,
"license": "MIT License",
"summary": "improvements over the standard zipfile package",
"version": "0.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "27167ed3633177023d6d186b9731128fa320d739f29defe47371db00ee1c75f9",
"md5": "2e11b9a44d9ae4783bc8837b76686e6d",
"sha256": "797e000fef6da0f25005d9c666ca8564ec70b8bf8521ddf51ff4cca8c8b35b36"
},
"downloads": -1,
"filename": "ruamel.std.zipfile-0.1.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "2e11b9a44d9ae4783bc8837b76686e6d",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 6545,
"upload_time": "2017-01-01T09:53:52",
"upload_time_iso_8601": "2017-01-01T09:53:52.906850Z",
"url": "https://files.pythonhosted.org/packages/27/16/7ed3633177023d6d186b9731128fa320d739f29defe47371db00ee1c75f9/ruamel.std.zipfile-0.1.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bdadf954e535b2ae686277be56a3164c4eb55743c469ad81750b0769a5718bb1",
"md5": "cf7153801cfd1211e3fb68c73f684b94",
"sha256": "d7cc5ffdb24897670305d616ff2d864dbfc00c55b9b37dec2d08d046c76d1a30"
},
"downloads": -1,
"filename": "ruamel.std.zipfile-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "cf7153801cfd1211e3fb68c73f684b94",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11272,
"upload_time": "2017-01-01T09:53:39",
"upload_time_iso_8601": "2017-01-01T09:53:39.388485Z",
"url": "https://files.pythonhosted.org/packages/bd/ad/f954e535b2ae686277be56a3164c4eb55743c469ad81750b0769a5718bb1/ruamel.std.zipfile-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2017-01-01 09:53:39",
"github": false,
"gitlab": false,
"bitbucket": true,
"bitbucket_user": "ruamel",
"bitbucket_project": "std.zipfile",
"lcname": "ruamel.std.zipfile"
}