blob: 3e80b8a658c1fdd1b02f7b8848334c7e3e2fb6ec [file] [log] [blame]
// 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.
#include <memory>
#include <vector>
#include "file_interface.h"
namespace bsdiff {
class MemoryFile : public FileInterface {
// Creates a MemoryFile based on the underlying |file| passed. The MemoryFile
// will cache all the write in memory and write it to to |file| when it's
// closed. MemoryFile does not support read and seek.
// |size| should be the estimated total file size, it is used to reserve
// buffer space.
MemoryFile(std::unique_ptr<FileInterface> file, size_t size);
~MemoryFile() override;
// 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;
// The underlying FileInterace instance.
std::unique_ptr<FileInterface> file_;
std::vector<uint8_t> buffer_;
} // namespace bsdiff