From 0fe3dc70240ea62b56861ab830f9ab44644b18e5 Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Sat, 28 Nov 2020 14:36:59 -0600 Subject: [PATCH] Update libbrotli to 1.0.9 (stripped down to removing custom dictionary support) --- src/brotlicffi/_api.py | 21 ++---------- src/brotlicffi/_build.py | 25 +------------- test/test_simple_compression.py | 8 ----- diff --git a/src/brotlicffi/_api.py b/src/brotlicffi/_api.py index 49da0a3..8358d3f 100644 --- a/src/brotlicffi/_api.py +++ b/src/brotlicffi/_api.py @@ -95,8 +95,7 @@ def compress(data, mode=DEFAULT_MODE, quality=lib.BROTLI_DEFAULT_QUALITY, lgwin=lib.BROTLI_DEFAULT_WINDOW, - lgblock=0, - dictionary=b''): + lgblock=0): """ Compress a string using Brotli. @@ -124,11 +123,6 @@ def compress(data, based on ``quality``. :type lgblock: ``int`` - :param dictionary: A pre-set dictionary for LZ77. Please use this with - caution: if a dictionary is used for compression, the same dictionary - **must** be used for decompression! - :type dictionary: ``bytes`` - :returns: The compressed bytestring. :rtype: ``bytes`` """ @@ -141,8 +135,7 @@ def compress(data, mode=mode, quality=quality, lgwin=lgwin, - lgblock=lgblock, - dictionary=dictionary + lgblock=lgblock ) compressed_data = compressor._compress(data, lib.BROTLI_OPERATION_FINISH) assert lib.BrotliEncoderIsFinished(compressor._encoder) == lib.BROTLI_TRUE @@ -255,8 +248,7 @@ def __init__(self, mode=DEFAULT_MODE, quality=lib.BROTLI_DEFAULT_QUALITY, lgwin=lib.BROTLI_DEFAULT_WINDOW, - lgblock=0, - dictionary=b''): + lgblock=0): enc = lib.BrotliEncoderCreateInstance( ffi.NULL, ffi.NULL, ffi.NULL ) @@ -271,13 +263,6 @@ def __init__(self, _set_parameter(enc, lib.BROTLI_PARAM_LGWIN, "lgwin", lgwin) _set_parameter(enc, lib.BROTLI_PARAM_LGBLOCK, "lgblock", lgblock) - if dictionary: - self._dictionary = ffi.new("uint8_t []", dictionary) - self._dictionary_size = len(dictionary) - lib.BrotliEncoderSetCustomDictionary( - enc, self._dictionary_size, self._dictionary - ) - self._encoder = enc def _compress(self, data, operation): diff --git a/src/brotlicffi/_build.py b/src/brotlicffi/_build.py index d2a2d85..45dccb6 100644 --- a/src/brotlicffi/_build.py +++ b/src/brotlicffi/_build.py @@ -93,20 +93,6 @@ uint8_t** next_out, size_t* total_out); - /* Fills the new state with a dictionary for LZ77, warming up the - ringbuffer, e.g. for custom static dictionaries for data formats. - Not to be confused with the built-in transformable dictionary of Brotli. - |size| should be less or equal to 2^24 (16MiB), otherwise the dictionary - will be ignored. The dictionary must exist in memory until decoding is - done and is owned by the caller. To use: - 1) Allocate and initialize state with BrotliCreateInstance - 2) Use BrotliSetCustomDictionary - 3) Use BrotliDecompressStream - 4) Clean up and free state with BrotliDestroyState - */ - void BrotliDecoderSetCustomDictionary( - BrotliDecoderState* s, size_t size, const uint8_t* dict); - /* Returns true, if decoder has some unconsumed output. Otherwise returns false. */ BROTLI_BOOL BrotliDecoderHasMoreOutput(const BrotliDecoderState* s); @@ -205,15 +191,6 @@ BrotliEncoderParameter p, uint32_t value); - /* Fills the new state with a dictionary for LZ77, warming up the - ringbuffer, e.g. for custom static dictionaries for data formats. - Not to be confused with the built-in transformable dictionary of Brotli. - To decode, use BrotliSetCustomDictionary() of the decoder with the same - dictionary. */ - void BrotliEncoderSetCustomDictionary(BrotliEncoderState* state, - size_t size, - const uint8_t* dict); - /* Check if encoder is in "finished" state, i.e. no more input is acceptable and no more output will be produced. Works only with BrotliEncoderCompressStream workflow. diff --git a/test/test_simple_compression.py b/test/test_simple_compression.py index 45c322d..a480587 100644 --- a/test/test_simple_compression.py +++ b/test/test_simple_compression.py @@ -110,14 +110,6 @@ def test_compressed_data_roundtrips(s): assert brotlicffi.decompress(brotlicffi.compress(s)) == s -@given(binary(), binary()) -def test_compressed_data_with_dictionaries(s, dictionary): - d = brotlicffi.Decompressor(dictionary) - compressed = brotlicffi.compress(s, dictionary=dictionary) - uncompressed = d.decompress(compressed) - assert uncompressed == s - - @given(binary()) def test_process_alias(s): c1 = brotlicffi.Compressor()