blob: a1ac8fa9b962086a4a8df66980ffe7f0aa4d0130 [file] [log] [blame]
Kelvin Zhang55624032021-12-20 12:13:24 -08001//
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 Zhang55624032021-12-20 12:13:24 -080021#include <string_view>
22
23namespace chromeos_update_engine {
24
Kelvin Zhang760c3342022-02-08 13:41:49 -080025using SinkFunc = std::function<size_t(const uint8_t*, size_t)>;
26
Kelvin Zhang55624032021-12-20 12:13:24 -080027// |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.
36Blob TryCompressBlob(std::string_view blob,
37 const std::vector<CompressedBlock>& block_info,
38 const bool zero_padding_enabled,
39 const CompressionAlgorithm compression_algo);
Kelvin Zhang760c3342022-02-08 13:41:49 -080040bool 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 Zhang55624032021-12-20 12:13:24 -080045
46Blob TryDecompressBlob(std::string_view blob,
47 const std::vector<CompressedBlock>& block_info,
48 const bool zero_padding_enabled);
49Blob TryDecompressBlob(const Blob& blob,
50 const std::vector<CompressedBlock>& block_info,
51 const bool zero_padding_enabled);
52
Kelvin Zhang55624032021-12-20 12:13:24 -080053std::ostream& operator<<(std::ostream& out, const CompressedBlockInfo& info);
54
55std::ostream& operator<<(std::ostream& out, const CompressedBlock& block);
56
57} // namespace chromeos_update_engine
58
59#endif