• 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 _BSDIFF_PATCH_WRITER_INTERFACE_H_
6 #define _BSDIFF_PATCH_WRITER_INTERFACE_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include "bsdiff/control_entry.h"
12 
13 namespace bsdiff {
14 
15 enum class BsdiffFormat {
16   kLegacy,
17   kBsdf2,
18   kEndsley,
19 };
20 
21 class PatchWriterInterface {
22  public:
23   virtual ~PatchWriterInterface() = default;
24 
25   // Initialize the patch writer for a patch where the new file will have
26   // |new_size| bytes.
27   virtual bool Init(size_t new_size) = 0;
28 
29   // Write the passed |data| buffer of length |size| to the Diff or Extra
30   // streams respectively. Each method can be called independently from each
31   // other and calls don't need to be a correlation with the AddControlEntry()
32   // until Close() is called.
33   virtual bool WriteDiffStream(const uint8_t* data, size_t size) = 0;
34   virtual bool WriteExtraStream(const uint8_t* data, size_t size) = 0;
35 
36   // Add a new control triplet entry to the patch. These triplets may be added
37   // at any point before calling Close(), regardless of whether the
38   // corresponding WriteDiffStream() and WriteExtraStream() have been called
39   // yet.
40   virtual bool AddControlEntry(const ControlEntry& entry) = 0;
41 
42   // Finalize the patch writing process and close the file.
43   virtual bool Close() = 0;
44 
45  protected:
46   PatchWriterInterface() = default;
47 };
48 
49 }  // namespace bsdiff
50 
51 #endif  // _BSDIFF_PATCH_WRITER_INTERFACE_H_
52