diff options
Diffstat (limited to 'include/bsdiff/memory_file.h')
-rw-r--r-- | include/bsdiff/memory_file.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/bsdiff/memory_file.h b/include/bsdiff/memory_file.h new file mode 100644 index 0000000..4100fd6 --- /dev/null +++ b/include/bsdiff/memory_file.h @@ -0,0 +1,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_ |