Add an argument parser in bsdiff
Add a parser of format, type and quality in the bsdiff main function.
This allow the bsdiff binary to choose between the BSDFF40|BSDF2 patch
format and compress the patch with desired algorithms.
Bug: 34220646
Test: unittest pass; generate brotli compressed patches with bsdiff
binary
Change-Id: Ia4f7941e4eca7e6047e2749315127d1cf4a988ee
diff --git a/patch_writer.cc b/patch_writer.cc
index 9c906c6..7bed2ca 100644
--- a/patch_writer.cc
+++ b/patch_writer.cc
@@ -26,19 +26,25 @@
namespace bsdiff {
+BsdiffPatchWriter::BsdiffPatchWriter(const std::string& patch_filename)
+ : patch_filename_(patch_filename), format_(BsdiffFormat::kLegacy) {
+ ctrl_stream_.reset(new BZ2Compressor());
+ diff_stream_.reset(new BZ2Compressor());
+ extra_stream_.reset(new BZ2Compressor());
+}
+
BsdiffPatchWriter::BsdiffPatchWriter(const std::string& patch_filename,
- BsdiffFormat format)
- : patch_filename_(patch_filename), format_(format) {
- if (format_ == BsdiffFormat::kLegacy) {
- ctrl_stream_ = CreateCompressor(CompressorType::kBZ2);
- diff_stream_ = CreateCompressor(CompressorType::kBZ2);
- extra_stream_ = CreateCompressor(CompressorType::kBZ2);
- } else {
- // TODO(xunchang) set different compression method according to the
- // compressed size for these streams.
- ctrl_stream_ = CreateCompressor(CompressorType::kBrotli);
- diff_stream_ = CreateCompressor(CompressorType::kBrotli);
- extra_stream_ = CreateCompressor(CompressorType::kBrotli);
+ CompressorType type,
+ int quality)
+ : patch_filename_(patch_filename), format_(BsdiffFormat::kBsdf2) {
+ if (type == CompressorType::kBZ2) {
+ ctrl_stream_.reset(new BZ2Compressor());
+ diff_stream_.reset(new BZ2Compressor());
+ extra_stream_.reset(new BZ2Compressor());
+ } else if (type == CompressorType::kBrotli) {
+ ctrl_stream_.reset(new BrotliCompressor(quality));
+ diff_stream_.reset(new BrotliCompressor(quality));
+ extra_stream_.reset(new BrotliCompressor(quality));
}
}