• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
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_PUFFDIFF_H_
6 #define SRC_INCLUDE_PUFFIN_PUFFDIFF_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "bsdiff/constants.h"
12 
13 #include "puffin/common.h"
14 #include "puffin/stream.h"
15 
16 namespace puffin {
17 
18 enum class PatchAlgorithm {
19   kBsdiff = 0,
20   kZucchini = 1,
21 };
22 
23 // Performs a diff operation between input deflate streams and creates a patch
24 // that is used in the client to recreate the |dst| from |src|.
25 // |src|          IN   Source deflate stream.
26 // |dst|          IN   Destination deflate stream.
27 // |src_deflates| IN   Deflate locations in |src|.
28 // |dst_deflates| IN   Deflate locations in |dst|.
29 // |compressors|  IN   Compressors to use in the underlying bsdiff, e.g.
30 // bz2,
31 //                     brotli.
32 // |patchAlgorithm|    IN   The patchAlgorithm used to create patches between
33 //                     uncompressed bytes, e.g. bsdiff, zucchini.
34 // |tmp_filepath| IN   A path to a temporary file. The caller has the
35 //                     responsibility of unlinking the file after the call to
36 //                     |PuffDiff| finishes.
37 // |puffin_patch| OUT  The patch that later can be used in |PuffPatch|.
38 bool PuffDiff(UniqueStreamPtr src,
39               UniqueStreamPtr dst,
40               const std::vector<BitExtent>& src_deflates,
41               const std::vector<BitExtent>& dst_deflates,
42               const std::vector<bsdiff::CompressorType>& compressors,
43               PatchAlgorithm patchAlgorithm,
44               const std::string& tmp_filepath,
45               Buffer* patch);
46 
47 // This function uses bsdiff as the patch algorithm.
48 bool PuffDiff(UniqueStreamPtr src,
49               UniqueStreamPtr dst,
50               const std::vector<BitExtent>& src_deflates,
51               const std::vector<BitExtent>& dst_deflates,
52               const std::vector<bsdiff::CompressorType>& compressors,
53               const std::string& tmp_filepath,
54               Buffer* patch);
55 
56 // Similar to the function above, except that it accepts raw buffer rather than
57 // stream.
58 bool PuffDiff(const Buffer& src,
59               const Buffer& dst,
60               const std::vector<BitExtent>& src_deflates,
61               const std::vector<BitExtent>& dst_deflates,
62               const std::vector<bsdiff::CompressorType>& compressors,
63               const std::string& tmp_filepath,
64               Buffer* patch);
65 
66 // The default puffdiff function that uses both bz2 and brotli to compress the
67 // patch data.
68 bool PuffDiff(const Buffer& src,
69               const Buffer& dst,
70               const std::vector<BitExtent>& src_deflates,
71               const std::vector<BitExtent>& dst_deflates,
72               const std::string& tmp_filepath,
73               Buffer* patch);
74 
75 }  // namespace puffin
76 
77 #endif  // SRC_INCLUDE_PUFFIN_PUFFDIFF_H_
78