Add the brotli compressor for bsdiff
Add a new compressor interface; and the brotli compressor which is
similar to the existing bz2 one.
Also add a new CompressorType argument to PatchWriter's init function;
this allows us to choose the right compressor based on the input option
in the future.
Bug: 34220646
Test: Run bsdiff/bspatch with brotli compressor/decompressor over a
list of files from angler's system image. Make succeeds.
Change-Id: Id9a3db2d7d051dcb751a1fc362f4c3b9226e878b
diff --git a/patch_writer.h b/patch_writer.h
index 83da26c..03e7c83 100644
--- a/patch_writer.h
+++ b/patch_writer.h
@@ -5,10 +5,11 @@
#ifndef _BSDIFF_PATCH_WRITER_H_
#define _BSDIFF_PATCH_WRITER_H_
+#include <memory>
#include <string>
#include <vector>
-#include "bsdiff/bz2_compressor.h"
+#include "bsdiff/compressor_interface.h"
#include "bsdiff/patch_writer_interface.h"
namespace bsdiff {
@@ -17,10 +18,9 @@
// BZ2-compressors and a 32-byte header.
class BsdiffPatchWriter : public PatchWriterInterface {
public:
- // Create the patch writer using the file |patch_filename| where the patch
- // data will be written to.
- explicit BsdiffPatchWriter(const std::string& patch_filename)
- : patch_filename_(patch_filename) {}
+ // Create the patch writer using |type| as the compression algorithm and the
+ // file |patch_filename| to write the patch data.
+ BsdiffPatchWriter(const std::string& patch_filename, CompressorType type);
// PatchWriterInterface overrides.
bool Init(size_t new_size) override;
@@ -43,9 +43,9 @@
std::string patch_filename_;
// The three internal compressed streams.
- BZ2Compressor ctrl_stream_;
- BZ2Compressor diff_stream_;
- BZ2Compressor extra_stream_;
+ std::unique_ptr<CompressorInterface> ctrl_stream_{nullptr};
+ std::unique_ptr<CompressorInterface> diff_stream_{nullptr};
+ std::unique_ptr<CompressorInterface> extra_stream_{nullptr};
};
} // namespace bsdiff