diff options
author | eustas <eustas.ru@gmail.com> | 2016-01-22 14:01:46 +0100 |
---|---|---|
committer | eustas <eustas.ru@gmail.com> | 2016-01-22 14:01:46 +0100 |
commit | 1f9106429a1926dee87d932b717c8ac4ab4f5c24 (patch) | |
tree | c7cbc3d8ee37a3a32c9b8e4667ac58e27762df37 /python | |
parent | bed93862608d4d232ebe6d229f04e48399775e8b (diff) | |
download | brotli-1f9106429a1926dee87d932b717c8ac4ab4f5c24.zip brotli-1f9106429a1926dee87d932b717c8ac4ab4f5c24.tar.gz brotli-1f9106429a1926dee87d932b717c8ac4ab4f5c24.tar.bz2 |
Remove deprecated API call
Diffstat (limited to 'python')
-rw-r--r-- | python/brotlimodule.cc | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/python/brotlimodule.cc b/python/brotlimodule.cc index 8755392..a84f947 100644 --- a/python/brotlimodule.cc +++ b/python/brotlimodule.cc @@ -150,12 +150,6 @@ static PyObject* brotli_compress(PyObject *self, PyObject *args, PyObject *keywd return ret; } -int output_callback(void* data, const uint8_t* buf, size_t count) { - std::vector<uint8_t> *output = (std::vector<uint8_t> *)data; - output->insert(output->end(), buf, buf + count); - return (int)count; -} - PyDoc_STRVAR(decompress__doc__, "Decompress a compressed byte string.\n" "\n" @@ -181,20 +175,33 @@ static PyObject* brotli_decompress(PyObject *self, PyObject *args) { if (!ok) return NULL; - BrotliMemInput memin; - BrotliInput in = BrotliInitMemInput(input, length, &memin); - - BrotliOutput out; std::vector<uint8_t> output; - out.cb_ = &output_callback; - out.data_ = &output; - - ok = BrotliDecompress(in, out); + const size_t kBufferSize = 65536; + uint8_t* buffer = new uint8_t[kBufferSize]; + BrotliState state; + BrotliStateInit(&state); + + BrotliResult result = BROTLI_RESULT_NEEDS_MORE_OUTPUT; + while (result == BROTLI_RESULT_NEEDS_MORE_OUTPUT) { + size_t available_out = kBufferSize; + uint8_t* next_out = buffer; + size_t total_out = 0; + result = BrotliDecompressStream(&length, &input, + &available_out, &next_out, + &total_out, &state); + size_t used_out = kBufferSize - available_out; + if (used_out != 0) + output->insert(output->end(), buffer, buffer + used_out); + } + ok = result == BROTLI_RESULT_SUCCESS; if (ok) { ret = PyBytes_FromStringAndSize((char*)(output.size() ? &output[0] : NULL), output.size()); } else { PyErr_SetString(BrotliError, "BrotliDecompress failed"); } + + BrotliStateCleanup(&state); + delete[] buffer; return ret; } |