huangcm
2025-07-01 676035278781360996553c427a12bf358249ebf7
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
// Copyright 2016 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_MEMORY_FILE_H_
#define _BSDIFF_MEMORY_FILE_H_
 
#include <memory>
 
#include "bsdiff/file_interface.h"
 
namespace bsdiff {
 
class MemoryFile : public FileInterface {
 public:
  // Creates a read only MemoryFile based on the underlying |data| passed.
  // The MemoryFile will use data starting from |data| with length of |size| as
  // the file content. Write is not supported.
  MemoryFile(const uint8_t* data, size_t size);
 
  ~MemoryFile() = default;
 
  // FileInterface overrides.
  bool Read(void* buf, size_t count, size_t* bytes_read) override;
  bool Write(const void* buf, size_t count, size_t* bytes_written) override;
  bool Seek(off_t pos) override;
  bool Close() override;
  bool GetSize(uint64_t* size) override;
 
 private:
  const uint8_t* data_ = nullptr;
  size_t size_ = 0;
  off_t offset_ = 0;
};
 
}  // namespace bsdiff
 
#endif  // _BSDIFF_MEMORY_FILE_H_