comparison mupdf-source/thirdparty/brotli/python/brotli.py @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 # Copyright 2016 The Brotli Authors. All rights reserved.
2 #
3 # Distributed under MIT license.
4 # See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5
6 """Functions to compress and decompress data using the Brotli library."""
7
8 import _brotli
9
10 # The library version.
11 version = __version__ = _brotli.__version__
12
13 # The compression mode.
14 MODE_GENERIC = _brotli.MODE_GENERIC
15 MODE_TEXT = _brotli.MODE_TEXT
16 MODE_FONT = _brotli.MODE_FONT
17
18 # The Compressor object.
19 Compressor = _brotli.Compressor
20
21 # The Decompressor object.
22 Decompressor = _brotli.Decompressor
23
24 # Compress a byte string.
25 def compress(string, mode=MODE_GENERIC, quality=11, lgwin=22, lgblock=0):
26 """Compress a byte string.
27
28 Args:
29 string (bytes): The input data.
30 mode (int, optional): The compression mode; value 0 should be used for
31 generic input (MODE_GENERIC); value 1 might be beneficial for UTF-8 text
32 input (MODE_TEXT); value 2 tunes encoder for WOFF 2.0 data (MODE_FONT).
33 Defaults to 0.
34 quality (int, optional): Controls the compression-speed vs compression-
35 density tradeoff. The higher the quality, the slower the compression.
36 Range is 0 to 11. Defaults to 11.
37 lgwin (int, optional): Base 2 logarithm of the sliding window size. Range
38 is 10 to 24. Defaults to 22.
39 lgblock (int, optional): Base 2 logarithm of the maximum input block size.
40 Range is 16 to 24. If set to 0, the value will be set based on the
41 quality. Defaults to 0.
42
43 Returns:
44 The compressed byte string.
45
46 Raises:
47 brotli.error: If arguments are invalid, or compressor fails.
48 """
49 compressor = Compressor(mode=mode, quality=quality, lgwin=lgwin,
50 lgblock=lgblock)
51 return compressor.process(string) + compressor.finish()
52
53 # Decompress a compressed byte string.
54 decompress = _brotli.decompress
55
56 # Raised if compression or decompression fails.
57 error = _brotli.error