Kelvin Zhang | 5562403 | 2021-12-20 12:13:24 -0800 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2021 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #ifndef UPDATE_ENGINE_LZ4DIFF_LZ4DIFF_COMPRESS_H_ |
| 18 | #define UPDATE_ENGINE_LZ4DIFF_LZ4DIFF_COMPRESS_H_ |
| 19 | |
| 20 | #include "lz4diff_format.h" |
| 21 | |
| 22 | #include <string_view> |
| 23 | |
| 24 | namespace chromeos_update_engine { |
| 25 | |
| 26 | // |TryCompressBlob| and |TryDecompressBlob| are inverse function of each other. |
| 27 | // One compresses data into fixed size output chunks, one decompresses fixed |
| 28 | // size blocks. |
| 29 | // The |TryCompressBlob| routine is supposed to mimic how EROFS compresses input |
| 30 | // files when creating an EROFS image. After calling |TryCompressBlob|, LZ4DIFF |
| 31 | // will compare the re-compressed blob and EROFS's ground truth blob, and |
| 32 | // generate a BSDIFF patch between them if there's mismatch. Therefore, it is OK |
| 33 | // that |TryCompressBlob| produces slightly different output than mkfs.erofs, so |
| 34 | // as long as |TryCompressBlob| exhibits consistne bebavior across platforms. |
| 35 | Blob TryCompressBlob(std::string_view blob, |
| 36 | const std::vector<CompressedBlock>& block_info, |
| 37 | const bool zero_padding_enabled, |
| 38 | const CompressionAlgorithm compression_algo); |
| 39 | |
| 40 | Blob TryDecompressBlob(std::string_view blob, |
| 41 | const std::vector<CompressedBlock>& block_info, |
| 42 | const bool zero_padding_enabled); |
| 43 | Blob TryDecompressBlob(const Blob& blob, |
| 44 | const std::vector<CompressedBlock>& block_info, |
| 45 | const bool zero_padding_enabled); |
| 46 | |
| 47 | [[nodiscard]] std::string_view ToStringView(const Blob& blob) noexcept; |
| 48 | |
| 49 | [[nodiscard]] std::string_view ToStringView(const void* data, |
| 50 | size_t size) noexcept; |
| 51 | |
| 52 | std::ostream& operator<<(std::ostream& out, const CompressedBlockInfo& info); |
| 53 | |
| 54 | std::ostream& operator<<(std::ostream& out, const CompressedBlock& block); |
| 55 | |
| 56 | } // namespace chromeos_update_engine |
| 57 | |
| 58 | #endif |