Home | History | Annotate | Download | only in bsdiff
      1 // 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>
      9 
     10 #include "bsdiff/file_interface.h"
     11 
     12 namespace bsdiff {
     13 
     14 class MemoryFile : public FileInterface {
     15  public:
     16   // 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);
     20 
     21   ~MemoryFile() = default;
     22 
     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:
     31   const uint8_t* data_ = nullptr;
     32   size_t size_ = 0;
     33   off_t offset_ = 0;
     34 };
     35 
     36 }  // namespace bsdiff
     37 
     38 #endif  // _BSDIFF_MEMORY_FILE_H_
     39