lin
2025-07-30 fcd736bf35fd93b563e9bbf594f2aa7b62028cc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
#ifndef _BSDIFF_FILE_INTERFACE_H_
#define _BSDIFF_FILE_INTERFACE_H_
 
#include <sys/types.h>
 
#include <stddef.h>
#include <stdint.h>
 
#include "bsdiff/common.h"
 
static_assert(sizeof(off_t) == sizeof(int64_t),
              "off_t must be a 64-bit number, use -D_FILE_OFFSET_BITS=64");
 
namespace bsdiff {
 
class BSDIFF_EXPORT FileInterface {
 public:
  virtual ~FileInterface() = default;
 
  // Reads synchronously from the current file position up to |count| bytes into
  // the passed |buf| buffer. On success, stores in |bytes_read| how many bytes
  // were actually read from the file. In case of error returns false. This
  // method may read less than |count| bytes even if there's no error. If the
  // end of file is reached, 0 bytes will be read and this methods returns true.
  virtual bool Read(void* buf, size_t count, size_t* bytes_read) = 0;
 
  // Writes synchronously up to |count| bytes from to passed |buf| buffer to
  // the file. On success, stores in |bytes_written| how many bytes
  // were actually written to the file. This method may write less than |count|
  // bytes and return successfully, or even write 0 bytes if there's no more
  // space left on the device. Returns whether the write succeeded.
  virtual bool Write(const void* buf, size_t count, size_t* bytes_written) = 0;
 
  // Change the current file position to |pos| bytes from the beginning of the
  // file. Return whether the seek succeeded.
  virtual bool Seek(off_t pos) = 0;
 
  // Closes the file and flushes any cached data. Returns whether the close
  // succeeded.
  virtual bool Close() = 0;
 
  // Compute the size of the file and store it in |size|. Returns whether it
  // computed the size successfully.
  virtual bool GetSize(uint64_t* size) = 0;
 
 protected:
  FileInterface() = default;
};
 
}  // namespace bsdiff
 
#endif  // _BSDIFF_FILE_INTERFACE_H_