README.rst
1|Build Status|
2
3PYZOPFLI
4========
5
6cPython bindings for
7`zopfli <http://googledevelopers.blogspot.com/2013/02/compress-data-more-densely-with-zopfli.html>`__.
8
9USAGE
10=====
11
12pyzopfli is a straight forward wrapper around zopfli's ZlibCompress method.
13
14::
15
16 from zopfli.zlib import compress
17 from zlib import decompress
18 s = 'Hello World'
19 print decompress(compress(s))
20
21pyzopfli also wraps GzipCompress, but the API point does not try to
22mimic the gzip module.
23
24::
25
26 from zopfli.gzip import compress
27 from StringIO import StringIO
28 from gzip import GzipFile
29 print GzipFile(fileobj=StringIO(compress("Hello World!"))).read()
30
31Both zopfli.zlib.compress and zopfli.gzip.compress support the following
32keyword arguments. All values should be integers; boolean parmaters are
33treated as expected, 0 and >0 as false and true.
34
35- *verbose* dumps zopfli debugging data to stderr
36
37- *numiterations* Maximum amount of times to rerun forward and backward
38 pass to optimize LZ77 compression cost. Good values: 10, 15 for small
39 files, 5 for files over several MB in size or it will be too slow.
40
41- *blocksplitting* If true, splits the data in multiple deflate blocks
42 with optimal choice for the block boundaries. Block splitting gives
43 better compression. Default: true (1).
44
45- *blocksplittinglast* If true, chooses the optimal block split points
46 only after doing the iterative LZ77 compression. If false, chooses
47 the block split points first, then does iterative LZ77 on each
48 individual block. Depending on the file, either first or last gives
49 the best compression. Default: false (0).
50
51- *blocksplittingmax* Maximum amount of blocks to split into (0 for
52 unlimited, but this can give extreme results that hurt compression on
53 some files). Default value: 15.
54
55TODO
56====
57
58- Stop reading the entire file into memory and support streaming
59
60- Monkey patch zlib and gzip so code with an overly tight binding can
61 be easily modified to use zopfli.
62
63.. |Build Status| image:: https://github.com/fonttools/py-zopfli/actions/workflows/ci.yml/badge.svg?branch=master
64 :target: https://github.com/fonttools/py-zopfli/actions/workflows/ci.yml
65