xref: /aosp_15_r20/external/puffin/src/include/puffin/puffpatch.h (revision 07fb1d065b7cfb4729786fadd42a612532d2f466)
1 // Copyright 2017 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef SRC_INCLUDE_PUFFIN_PUFFPATCH_H_
6 #define SRC_INCLUDE_PUFFIN_PUFFPATCH_H_
7 
8 #include "puffin/common.h"
9 #include "puffin/stream.h"
10 
11 namespace puffin {
12 
13 extern const char kMagic[];
14 extern const size_t kMagicLength;
15 constexpr size_t kDefaultCacheSize = 64 * 1024;  // Total 64K cache.
16 
17 // Applies the puffin patch to deflate stream |src| to create deflate stream
18 // |dst|. This function is used in the client and internally uses bspatch to
19 // apply the patch. The input streams are of type |shared_ptr| because
20 // |PuffPatch| needs to wrap these streams into another ones and we don't want
21 // to loose the ownership of the input streams. Optionally one can cache the
22 // puff buffers individually if non-zero value is passed |max_cache_size|.
23 //
24 // |src|           IN  Source deflate stream.
25 // |dst|           IN  Destination deflate stream.
26 // |patch|         IN  The input patch.
27 // |patch_length|  IN  The length of the patch.
28 // |max_cache_size|IN  The maximum amount of memory to cache puff buffers.
29 bool PuffPatch(UniqueStreamPtr src,
30                UniqueStreamPtr dst,
31                const uint8_t* patch,
32                size_t patch_length,
33                size_t max_cache_size = kDefaultCacheSize);
34 
35 }  // namespace puffin
36 
37 #endif  // SRC_INCLUDE_PUFFIN_PUFFPATCH_H_
38