aboutsummaryrefslogtreecommitdiff
path: root/python/brotli.py
diff options
context:
space:
mode:
authorAlex Nicksay <nicksay@gmail.com>2016-10-24 07:28:56 -0400
committerEugene Kliuchnikov <eustas@google.com>2016-10-24 13:28:56 +0200
commit5632315d3568b4bba3966a69c195adeabaf2fc0b (patch)
tree245b4508711d453be23f6b9b512c6c6af122a859 /python/brotli.py
parent678f8627d3d2d6cdc92050a23041269b33febb0a (diff)
downloadbrotli-5632315d3568b4bba3966a69c195adeabaf2fc0b.zip
brotli-5632315d3568b4bba3966a69c195adeabaf2fc0b.tar.gz
brotli-5632315d3568b4bba3966a69c195adeabaf2fc0b.tar.bz2
Python: Support streamed compression with the Compressor object (#448)
This adds `flush` and `finish` methods to the `Compressor` object in the extension module, renames the `compress` method to `process`, and updates that method to only process data. Now, one or more `process` calls followed by a `finish` call will be equivalent to a module-level `compress` call. Note: To maximize the compression efficiency (and match underlying Brotli behavior, the `Compressor` object `process` method does not guarantee all input is immediately written to output. To ensure immediate output, call `flush` to manually flush the compression buffer. Extraneous flushing can increase the size, but may be required when processing streaming data. Progress on #191
Diffstat (limited to 'python/brotli.py')
-rw-r--r--python/brotli.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/python/brotli.py b/python/brotli.py
index f3f56b8..a88616e 100644
--- a/python/brotli.py
+++ b/python/brotli.py
@@ -34,7 +34,7 @@ def compress(string, mode=MODE_GENERIC, quality=11, lgwin=22, lgblock=0,
Range is 16 to 24. If set to 0, the value will be set based on the
quality. Defaults to 0.
dictionary (bytes, optional): Custom dictionary. Only last sliding window
- size bytes will be used.
+ size bytes will be used.
Returns:
The compressed byte string.
@@ -44,7 +44,7 @@ def compress(string, mode=MODE_GENERIC, quality=11, lgwin=22, lgblock=0,
"""
compressor = _brotli.Compressor(mode=mode, quality=quality, lgwin=lgwin,
lgblock=lgblock, dictionary=dictionary)
- return compressor.compress(string)
+ return compressor.process(string) + compressor.finish()
# Decompress a compressed byte string.
decompress = _brotli.decompress