| #pragma once |
| |
| #include "image_handler.hpp" |
| |
| #include <cstdint> |
| #include <fstream> |
| #include <memory> |
| #include <string> |
| #include <vector> |
| |
| namespace ipmi_flash |
| { |
| |
| class FileHandler : public ImageHandlerInterface |
| { |
| public: |
| /** |
| * Create a FileHandler. This object is basically a filewriter. |
| * |
| * @param[in] filename - file to use for the contents, fully |
| * qualified file system path. |
| */ |
| explicit FileHandler(const std::string& filename) : filename(filename) |
| {} |
| |
| bool open(const std::string& path, |
| std::ios_base::openmode mode = std::ios::out) override; |
| void close() override; |
| bool write(std::uint32_t offset, |
| const std::vector<std::uint8_t>& data) override; |
| virtual std::optional<std::vector<uint8_t>> |
| read(std::uint32_t offset, std::uint32_t size) override; |
| int getSize() override; |
| |
| private: |
| /** the active hash path, ignore. */ |
| std::string path; |
| |
| /** The file handle. */ |
| std::fstream file; |
| |
| /** The filename (including path) to use to write bytes. */ |
| std::string filename; |
| }; |
| |
| } // namespace ipmi_flash |