Add lz4 decompress/compress routines

During OTA generation, we decompress blobs on disk using lz4, and
perform diffing on the decompressed blobs. This is known to help OTA
size a lot. This CL adds decompression routines, following CLs will
start to actually call these routines.

Test: th
Bug: 206729162

Change-Id: Ifee87220e95740cb73a68ef84935c1cbb6a78666
diff --git a/lz4diff/lz4diff_compress.h b/lz4diff/lz4diff_compress.h
new file mode 100644
index 0000000..7cbb9ac
--- /dev/null
+++ b/lz4diff/lz4diff_compress.h
@@ -0,0 +1,58 @@
+//
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef UPDATE_ENGINE_LZ4DIFF_LZ4DIFF_COMPRESS_H_
+#define UPDATE_ENGINE_LZ4DIFF_LZ4DIFF_COMPRESS_H_
+
+#include "lz4diff_format.h"
+
+#include <string_view>
+
+namespace chromeos_update_engine {
+
+// |TryCompressBlob| and |TryDecompressBlob| are inverse function of each other.
+// One compresses data into fixed size output chunks, one decompresses fixed
+// size blocks.
+// The |TryCompressBlob| routine is supposed to mimic how EROFS compresses input
+// files when creating an EROFS image. After calling |TryCompressBlob|, LZ4DIFF
+// will compare the re-compressed blob and EROFS's ground truth blob, and
+// generate a BSDIFF patch between them if there's mismatch. Therefore, it is OK
+// that |TryCompressBlob| produces slightly different output than mkfs.erofs, so
+// as long as |TryCompressBlob| exhibits consistne bebavior across platforms.
+Blob TryCompressBlob(std::string_view blob,
+                     const std::vector<CompressedBlock>& block_info,
+                     const bool zero_padding_enabled,
+                     const CompressionAlgorithm compression_algo);
+
+Blob TryDecompressBlob(std::string_view blob,
+                       const std::vector<CompressedBlock>& block_info,
+                       const bool zero_padding_enabled);
+Blob TryDecompressBlob(const Blob& blob,
+                       const std::vector<CompressedBlock>& block_info,
+                       const bool zero_padding_enabled);
+
+[[nodiscard]] std::string_view ToStringView(const Blob& blob) noexcept;
+
+[[nodiscard]] std::string_view ToStringView(const void* data,
+                                            size_t size) noexcept;
+
+std::ostream& operator<<(std::ostream& out, const CompressedBlockInfo& info);
+
+std::ostream& operator<<(std::ostream& out, const CompressedBlock& block);
+
+}  // namespace chromeos_update_engine
+
+#endif