1*a3a45f30SXin Li // Copyright 2017 The Chromium OS Authors. All rights reserved. 2*a3a45f30SXin Li // Use of this source code is governed by a BSD-style license that can be 3*a3a45f30SXin Li // found in the LICENSE file. 4*a3a45f30SXin Li 5*a3a45f30SXin Li #ifndef _BSDIFF_BROTLI_COMPRESSOR_H_ 6*a3a45f30SXin Li #define _BSDIFF_BROTLI_COMPRESSOR_H_ 7*a3a45f30SXin Li 8*a3a45f30SXin Li #include <stdint.h> 9*a3a45f30SXin Li 10*a3a45f30SXin Li #include <vector> 11*a3a45f30SXin Li 12*a3a45f30SXin Li #include <brotli/encode.h> 13*a3a45f30SXin Li 14*a3a45f30SXin Li #include "bsdiff/compressor_buffer.h" 15*a3a45f30SXin Li #include "bsdiff/compressor_interface.h" 16*a3a45f30SXin Li #include "bsdiff/constants.h" 17*a3a45f30SXin Li 18*a3a45f30SXin Li namespace bsdiff { 19*a3a45f30SXin Li 20*a3a45f30SXin Li class BrotliCompressor : public CompressorInterface { 21*a3a45f30SXin Li public: 22*a3a45f30SXin Li // Create a brotli compressor with the compression quality |quality|. As the 23*a3a45f30SXin Li // value of quality increases, the compression becomes better but slower. 24*a3a45f30SXin Li // The valid range of quality is between BROTLI_MIN_QUALITY and 25*a3a45f30SXin Li // BROTLI_MAX_QUALITY; and the caller is responsible for the validity check. 26*a3a45f30SXin Li explicit BrotliCompressor(int quality); 27*a3a45f30SXin Li ~BrotliCompressor() override; 28*a3a45f30SXin Li 29*a3a45f30SXin Li // CompressorInterface overrides. 30*a3a45f30SXin Li bool Write(const uint8_t* buf, size_t size) override; 31*a3a45f30SXin Li bool Finish() override; 32*a3a45f30SXin Li const std::vector<uint8_t>& GetCompressedData() override; Type()33*a3a45f30SXin Li CompressorType Type() const override { return CompressorType::kBrotli; } 34*a3a45f30SXin Li 35*a3a45f30SXin Li private: 36*a3a45f30SXin Li BrotliEncoderState* brotli_encoder_state_; 37*a3a45f30SXin Li 38*a3a45f30SXin Li CompressorBuffer comp_buffer_; 39*a3a45f30SXin Li }; 40*a3a45f30SXin Li 41*a3a45f30SXin Li } // namespace bsdiff 42*a3a45f30SXin Li 43*a3a45f30SXin Li #endif // _BSDIFF_BROTLI_COMPRESSOR_H_ 44