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