{"id":29086380,"url":"https://github.com/danny0838/zipremove","last_synced_at":"2025-06-28T00:06:44.234Z","repository":{"id":299094521,"uuid":"1002065275","full_name":"danny0838/zipremove","owner":"danny0838","description":"Extends `zipfile` with `remove`-related functionalities","archived":false,"fork":false,"pushed_at":"2025-06-21T16:23:39.000Z","size":67,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-21T17:28:39.985Z","etag":null,"topics":["python3","zipfile"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/zipremove/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danny0838.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-14T16:33:03.000Z","updated_at":"2025-06-21T16:23:42.000Z","dependencies_parsed_at":"2025-06-21T17:23:04.503Z","dependency_job_id":null,"html_url":"https://github.com/danny0838/zipremove","commit_stats":null,"previous_names":["danny0838/zipremove"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/danny0838/zipremove","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danny0838%2Fzipremove","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danny0838%2Fzipremove/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danny0838%2Fzipremove/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danny0838%2Fzipremove/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danny0838","download_url":"https://codeload.github.com/danny0838/zipremove/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danny0838%2Fzipremove/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262352624,"owners_count":23297689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python3","zipfile"],"created_at":"2025-06-28T00:06:39.770Z","updated_at":"2025-06-28T00:06:44.226Z","avatar_url":"https://github.com/danny0838.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![PyPI version](https://img.shields.io/pypi/v/zipremove.svg)\n![Python Versions](https://img.shields.io/pypi/pyversions/zipremove)\n![Status](https://img.shields.io/pypi/status/zipremove)\n![License](https://img.shields.io/github/license/danny0838/zipremove)\n[![Downloads](https://static.pepy.tech/personalized-badge/zipremove?period=month\u0026left_text=Downloads)](https://pepy.tech/project/zipremove)\n[![Pull request](https://img.shields.io/github/pulls/detail/state/python/cpython/134627)](https://github.com/python/cpython/pull/134627)\n\nThis package extends `zipfile` with `remove`-related functionalities.\n\n## API\n\n* `ZipFile.remove(zinfo_or_arcname)`\n\n   Removes a member from the archive.  *zinfo_or_arcname* may be the full path\n   of the member or a `ZipInfo` instance.\n\n   If multiple members share the same full path, only one is removed when\n   a path is provided.\n\n   This does not physically remove the local file entry from the archive.\n   Call `repack` afterwards to reclaim space.\n\n   The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.\n\n   Returns the removed `ZipInfo` instance.\n\n   Calling `remove` on a closed ZipFile will raise a `ValueError`.\n\n* `ZipFile.repack(removed=None, *, strict_descriptor=False[, chunk_size])`\n\n   Rewrites the archive to remove stale local file entries, shrinking its file\n   size.\n\n   If *removed* is provided, it must be a sequence of `ZipInfo` objects\n   representing removed entries; only their corresponding local file entries\n   will be removed.\n\n   If *removed* is not provided, the archive is scanned to identify and remove\n   local file entries that are no longer referenced in the central directory.\n   The algorithm assumes that local file entries (and the central directory,\n   which is mostly treated as the \"last entry\") are stored consecutively:\n\n   1. Data before the first referenced entry is removed only when it appears to\n      be a sequence of consecutive entries with no extra following bytes; extra\n      preceding bytes are preserved.\n   2. Data between referenced entries is removed only when it appears to\n      be a sequence of consecutive entries with no extra preceding bytes; extra\n      following bytes are preserved.\n   3. Entries must not overlap. If any entry's data overlaps with another, a\n      `BadZipFile` error is raised and no changes are made.\n\n   When scanning, setting `strict_descriptor=True` disables detection of any\n   entry using an unsigned data descriptor (deprecated in the ZIP specification\n   since version 6.3.0, released on 2006-09-29, and used only by some legacy\n   tools). This improves performance, but may cause some stale entries to be\n   preserved.\n\n   *chunk_size* may be specified to control the buffer size when moving\n   entry data (default is 1 MiB).\n\n   The archive must be opened with mode ``'a'``.\n\n   Calling `repack` on a closed ZipFile will raise a `ValueError`.\n\n* `ZipFile.copy(zinfo_or_arcname, new_arcname[, chunk_size])`\n\n   Copies a member *zinfo_or_arcname* to *new_arcname* in the archive.\n   *zinfo_or_arcname* may be the full path of the member or a `ZipInfo`\n   instance.\n\n   *chunk_size* may be specified to control the buffer size when copying\n   entry data (default is 1 MiB).\n\n   The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``, and the\n   underlying stream must be seekable.\n\n   Returns the original version of the copied `ZipInfo` instance.\n\n   Calling `copy` on a closed ZipFile will raise a `ValueError`.\n\n\n## Examples\n\n### Remove entries and reclaim space\n\nCall `repack` after `remove`s to reclaim the space of the removed entries:\n\n```python\nimport os\nimport zipremove as zipfile\n\nwith zipfile.ZipFile('archive.zip', 'w') as zh:\n    zh.writestr('file1', 'content1')\n    zh.writestr('file2', 'content2')\n    zh.writestr('file3', 'content3')\n    zh.writestr('file4', 'content4')\n\nprint(os.path.getsize('archive.zip'))  # 398\n\nwith zipfile.ZipFile('archive.zip', 'a') as zh:\n    zh.remove('file1')\n    zh.remove('file2')\n    zh.remove('file3')\n    zh.repack()\n\nprint(os.path.getsize('archive.zip'))  # 116 (would be 245 without `repack`)\n```\n\nAlternatively, pass the ZipInfo objects of the removed entries, for better\nperformance and error-proofing:\n\n```python\nimport os\nimport zipremove as zipfile\n\nwith zipfile.ZipFile('archive.zip', 'w') as zh:\n    zh.writestr('file1', 'content1')\n    zh.writestr('file2', 'content2')\n    zh.writestr('file3', 'content3')\n    zh.writestr('file4', 'content4')\n\nprint(os.path.getsize('archive.zip'))  # 398\n\nwith zipfile.ZipFile('archive.zip', 'a') as zh:\n    zinfos = []\n    zinfos.append(zh.remove('file1'))\n    zinfos.append(zh.remove('file2'))\n    zinfos.append(zh.remove('file3'))\n    zh.repack(zinfos)\n\nprint(os.path.getsize('archive.zip'))  # 116 (would be 245 without `repack`)\n```\n\n### Move entries under a folder and reclaim space\n\nMoving entries in a ZIP file must be done as a combination of `copy`, `remove`,\nand optionally `repack`, because every local file entry contains the filename\nand requires rewriting.\n\n```python\nimport os\nimport zipremove as zipfile\n\nwith zipfile.ZipFile('archive.zip', 'w') as zh:\n    zh.writestr('file0', 'content0')\n    zh.writestr('folder1/file1', 'content1')\n    zh.writestr('folder1/file2', 'content2')\n    zh.writestr('folder1/file3', 'content3')\n\nprint(os.path.getsize('archive.zip'))  # 446\n\nwith zipfile.ZipFile('archive.zip', 'a') as zh:\n    for n in zh.namelist():\n        if n.startswith('folder1/'):\n            n2 = 'folder2/' + n[len('folder1/'):]\n            zh.copy(n, n2)\n            zh.remove(n)\n    zh.repack()\n\nprint(os.path.getsize('archive.zip'))  # 446 (would be 599 without `repack`)\n```\n\nSimilarly, pass the ZipInfo objects of the copied/removed entries for better\nperformance and error-proofing:\n\n```python\nimport os\nimport zipremove as zipfile\n\nwith zipfile.ZipFile('archive.zip', 'w') as zh:\n    zh.writestr('file0', 'content0')\n    zh.writestr('folder1/file1', 'content1')\n    zh.writestr('folder1/file2', 'content2')\n    zh.writestr('folder1/file3', 'content3')\n\nprint(os.path.getsize('archive.zip'))  # 446\n\nwith zipfile.ZipFile('archive.zip', 'a') as zh:\n    zinfos = []\n    for n in zh.namelist():\n        if n.startswith('folder1/'):\n            n2 = 'folder2/' + n[len('folder1/'):]\n            zinfos.append(zh.remove(zh.copy(n, n2)))\n    zh.repack(zinfos)\n\nprint(os.path.getsize('archive.zip'))  # 446 (would be 599 without `repack`)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanny0838%2Fzipremove","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanny0838%2Fzipremove","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanny0838%2Fzipremove/lists"}