1 #pragma once
2 
3 #include "image_handler.hpp"
4 
5 #include <cstdint>
6 #include <fstream>
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace ipmi_flash
12 {
13 
14 class FileHandler : public ImageHandlerInterface
15 {
16   public:
17     /**
18      * Create a FileHandler.  This object is basically a filewriter.
19      *
20      * @param[in] filename - file to use for the contents, fully
21      * qualified file system path.
22      */
23     explicit FileHandler(const std::string& filename) : filename(filename) {}
24 
25     bool open(const std::string& path,
26               std::ios_base::openmode mode = std::ios::out) override;
27     void close() override;
28     bool write(std::uint32_t offset,
29                const std::vector<std::uint8_t>& data) override;
30     virtual std::optional<std::vector<uint8_t>>
31         read(std::uint32_t offset, std::uint32_t size) override;
32     int getSize() override;
33 
34   private:
35     /** the active hash path, ignore. */
36     std::string path;
37 
38     /** The file handle. */
39     std::fstream file;
40 
41     /** The filename (including path) to use to write bytes. */
42     std::string filename;
43 };
44 
45 } // namespace ipmi_flash
46