| 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" | 
| Kelvin Zhang | 5562403 | 2021-12-20 12:13:24 -0800 | [diff] [blame] | 21 | #include <string_view> | 
|  | 22 |  | 
|  | 23 | namespace chromeos_update_engine { | 
|  | 24 |  | 
| Kelvin Zhang | 760c334 | 2022-02-08 13:41:49 -0800 | [diff] [blame] | 25 | using SinkFunc = std::function<size_t(const uint8_t*, size_t)>; | 
|  | 26 |  | 
| Kelvin Zhang | 5562403 | 2021-12-20 12:13:24 -0800 | [diff] [blame] | 27 | // |TryCompressBlob| and |TryDecompressBlob| are inverse function of each other. | 
|  | 28 | // One compresses data into fixed size output chunks, one decompresses fixed | 
|  | 29 | // size blocks. | 
|  | 30 | // The |TryCompressBlob| routine is supposed to mimic how EROFS compresses input | 
|  | 31 | // files when creating an EROFS image. After calling |TryCompressBlob|, LZ4DIFF | 
|  | 32 | // will compare the re-compressed blob and EROFS's ground truth blob, and | 
|  | 33 | // generate a BSDIFF patch between them if there's mismatch. Therefore, it is OK | 
|  | 34 | // that |TryCompressBlob| produces slightly different output than mkfs.erofs, so | 
|  | 35 | // as long as |TryCompressBlob| exhibits consistne bebavior across platforms. | 
|  | 36 | Blob TryCompressBlob(std::string_view blob, | 
|  | 37 | const std::vector<CompressedBlock>& block_info, | 
|  | 38 | const bool zero_padding_enabled, | 
|  | 39 | const CompressionAlgorithm compression_algo); | 
| Kelvin Zhang | 760c334 | 2022-02-08 13:41:49 -0800 | [diff] [blame] | 40 | bool TryCompressBlob(std::string_view blob, | 
|  | 41 | const std::vector<CompressedBlock>& block_info, | 
|  | 42 | const bool zero_padding_enabled, | 
|  | 43 | const CompressionAlgorithm compression_algo, | 
|  | 44 | const SinkFunc& sink); | 
| Kelvin Zhang | 5562403 | 2021-12-20 12:13:24 -0800 | [diff] [blame] | 45 |  | 
|  | 46 | Blob TryDecompressBlob(std::string_view blob, | 
|  | 47 | const std::vector<CompressedBlock>& block_info, | 
|  | 48 | const bool zero_padding_enabled); | 
|  | 49 | Blob TryDecompressBlob(const Blob& blob, | 
|  | 50 | const std::vector<CompressedBlock>& block_info, | 
|  | 51 | const bool zero_padding_enabled); | 
|  | 52 |  | 
| Kelvin Zhang | 5562403 | 2021-12-20 12:13:24 -0800 | [diff] [blame] | 53 | std::ostream& operator<<(std::ostream& out, const CompressedBlockInfo& info); | 
|  | 54 |  | 
|  | 55 | std::ostream& operator<<(std::ostream& out, const CompressedBlock& block); | 
|  | 56 |  | 
|  | 57 | }  // namespace chromeos_update_engine | 
|  | 58 |  | 
|  | 59 | #endif |