blob: 4100fd67c55b04706259d491e6f2c26c75ba3b96 [file] [log] [blame]
Sen Jiang5b372b62016-03-28 16:14:35 -07001// Copyright 2016 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_MEMORY_FILE_H_
6#define _BSDIFF_MEMORY_FILE_H_
7
8#include <memory>
Sen Jiang5b372b62016-03-28 16:14:35 -07009
Alex Deymoddf9db52017-03-02 16:10:41 -080010#include "bsdiff/file_interface.h"
Sen Jiang5b372b62016-03-28 16:14:35 -070011
12namespace bsdiff {
13
14class MemoryFile : public FileInterface {
15 public:
Sen Jiang716d5692016-05-09 16:43:34 -070016 // Creates a read only MemoryFile based on the underlying |data| passed.
17 // The MemoryFile will use data starting from |data| with length of |size| as
18 // the file content. Write is not supported.
19 MemoryFile(const uint8_t* data, size_t size);
Sen Jiang5b372b62016-03-28 16:14:35 -070020
Sen Jiang716d5692016-05-09 16:43:34 -070021 ~MemoryFile() = default;
Sen Jiang5b372b62016-03-28 16:14:35 -070022
23 // FileInterface overrides.
24 bool Read(void* buf, size_t count, size_t* bytes_read) override;
25 bool Write(const void* buf, size_t count, size_t* bytes_written) override;
26 bool Seek(off_t pos) override;
27 bool Close() override;
28 bool GetSize(uint64_t* size) override;
29
30 private:
Sen Jiang716d5692016-05-09 16:43:34 -070031 const uint8_t* data_ = nullptr;
32 size_t size_ = 0;
33 off_t offset_ = 0;
Sen Jiang5b372b62016-03-28 16:14:35 -070034};
35
36} // namespace bsdiff
37
38#endif // _BSDIFF_MEMORY_FILE_H_