Skip to main content

Rewrite zip files, modifying compression type and parameters.

Project description

zipmanip

This is a command line utility that rewrites a zip file. It attempts to leave the archive contents metadata and ordering as unchanged as is possible, but recompresses or decompresses the contents.

This was written to use as a git smudge/clean filter to use when using git to keep a history of zip files. (See below for more on that.)

It may be useful in other cases as well.

Usage with Git

Zipmanip can be used as a clean/smudge filter with git so that zip archives are stored uncompressed in the git index.

(The motivation is that if the zip contents are not compressed, git should be able to more efficiently pack the deltas between revisions.)

To set this up:

git config filter.zipmanip.clean "zipmanip --compression-method=store"
git config filter.zipmanip.smudge "zipmanip -9"
# optionally, for diff formatting
git config diff.unzip.textconv "unzip -c -a"

Then, edit .gitattributes to set the filter=zipmanip (and, optionally diff=unzip) on any zip files that you want to store uncompressed. E.g.

*.FCStd binary filter=zipmanip diff=unzip
*.3mf binary filter=zipmanip diff=unzip
*.amf binary filter=zipmanip diff=unzip

Bugs

On Round-trip Idempotentency

Currently if a zip archive is round tripped — converted to uncompressed, then recompressed — the result will not be byte-wise identical to the original. This is due to (at least) a couple of issues.

Differing compression algorithm and parameters

It may be possible to improve this situation, at least partially, by storing information on the original compression type in the uncompressed archives.

Note that data on compression level may be available from bits 1, 2 and possibly 4 of the ZipInfo.flags. (See section 4.4.4 of PKZIP Application Note.)

Differing use of "zip64" extended header

Also the use of "extended local header" is not preserved. (This manifests in .3mf files written by PrusaSlicer. PrusaSlicer always writes extended headers. (This, I think could be fixed with appropriate use of the force_zip64 parameters to ZipFile.open.)

Author

Jeff Dairiki dairiki@dairiki.org

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

zipmanip-0.1.0a2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zipmanip-0.1.0a2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file zipmanip-0.1.0a2.tar.gz.

File metadata

  • Download URL: zipmanip-0.1.0a2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for zipmanip-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 6e910140ae0ae70fe74cf9674d7e11d3eb3c2e7c96f9c04449486cc3233fce59
MD5 5a7d8645ca2a1187fe31abc74a957bf0
BLAKE2b-256 cf585cc5505ca8520c8a774c0eaf32b08591af11a9cd525e14efea723387017f

See more details on using hashes here.

File details

Details for the file zipmanip-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: zipmanip-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for zipmanip-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 54cf8dda5c380cd5b560cd2df9c283729a76a5bbaed6e4f83710e3acd2b41f5e
MD5 5fca403c01f508987d2e19413a796427
BLAKE2b-256 da248d11d1435ea97d5e0b88a0e0ab9b6b4603b0c064986aed7baaec9fbd8cfb

See more details on using hashes here.

Supported by

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