https://github.com/hattya/zopflipy
A Python bindings for Zopfli
https://github.com/hattya/zopflipy
compression python zlib zopfli
Last synced: 2 months ago
JSON representation
A Python bindings for Zopfli
- Host: GitHub
- URL: https://github.com/hattya/zopflipy
- Owner: hattya
- License: apache-2.0
- Created: 2015-05-11T12:54:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-02-09T13:28:52.000Z (8 months ago)
- Last Synced: 2025-03-27T21:11:49.028Z (7 months ago)
- Topics: compression, python, zlib, zopfli
- Language: Python
- Size: 99.6 KB
- Stars: 18
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
ZopfliPy
========A Python_ bindings for Zopfli_.
.. image:: https://img.shields.io/pypi/v/zopflipy.svg
:target: https://pypi.org/project/zopflipy.. image:: https://github.com/hattya/zopflipy/actions/workflows/ci.yml/badge.svg
:target: https://github.com/hattya/zopflipy/actions/workflows/ci.yml.. image:: https://ci.appveyor.com/api/projects/status/98a7e7d6qlkvs6vl/branch/master?svg=true
:target: https://ci.appveyor.com/project/hattya/zopflipy.. image:: https://codecov.io/gh/hattya/zopflipy/branch/master/graph/badge.svg
:target: https://codecov.io/gh/hattya/zopflipy.. _Python: https://www.python.org/
.. _Zopfli: https://github.com/google/zopfliInstallation
------------.. code:: console
$ pip install zopflipy
Requirements
------------- Python 3.9+
Usage
-----ZopfliCompressor
~~~~~~~~~~~~~~~~.. code:: pycon
>>> import zopfli
>>> c = zopfli.ZopfliCompressor(zopfli.ZOPFLI_FORMAT_DEFLATE)
>>> z = c.compress(b'Hello, world!') + c.flush()
>>> d = zopfli.ZopfliDecompressor(zopfli.ZOPFLI_FORMAT_DEFLATE)
>>> d.decompress(z) + d.flush()
b'Hello, world!''ZopfliDeflater
~~~~~~~~~~~~~~.. code:: pycon
>>> import zopfli
>>> c = zopfli.ZopfliDeflater()
>>> z = c.compress(b'Hello, world!') + c.flush()
>>> d = zopfli.ZopfliDecompressor(zopfli.ZOPFLI_FORMAT_DEFLATE)
>>> d.decompress(z) + d.flush()
b'Hello, world!''ZopfliPNG
~~~~~~~~~.. code:: pycon
>>> import zopfli
>>> png = zopfli.ZopfliPNG()
>>> with open('in.png', 'rb') as fp:
... data = fp.read()
>>> len(png.optimize(data)) < len(data)
TrueZipFile
~~~~~~~A subclass of |zipfile.ZipFile|_ which uses |ZopfliCompressor|_ for the
|zipfile.ZIP_DEFLATED|_ compression method... code:: pycon
>>> import zipfile
>>> import zopfli
>>> with zopfli.ZipFile('a.zip', 'w', zipfile.ZIP_DEFLATED) as zf:
... zf.writestr('a.txt', b'Hello, world!').. |zipfile.ZipFile| replace:: ``zipfile.ZipFile``
.. _zipfile.ZipFile: https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile
.. |ZopfliCompressor| replace:: ``ZopfliCompressor``
.. |zipfile.ZIP_DEFLATED| replace:: ``zipfile.ZIP_DEFLATED``
.. _zipfile.ZIP_DEFLATED: https://docs.python.org/3/library/zipfile.html#zipfile.ZIP_DEFLATEDLicense
-------ZopfliPy is distributed under the terms of the Apache License, Version 2.0.