add in memory read and write for file2

This commit is contained in:
2024-04-03 21:03:04 +02:00
parent 17b4cce69b
commit 659b410caa
3 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#pragma once
#include "./file2.hpp"
// write to vector or read from span
// no seeking for now (could make sense for read)
struct File2MemW : public File2I {
std::vector<uint8_t>& _mem;
File2MemW(std::vector<uint8_t>& mem);
virtual ~File2MemW(void);
bool isGood(void) override;
bool write(const ByteSpan data, int64_t pos = -1) override;
std::variant<ByteSpan, std::vector<uint8_t>> read(uint64_t size, int64_t pos = -1) override;
};
struct File2MemR : public File2I {
ByteSpan _mem;
int64_t _read_pos{0};
File2MemR(ByteSpan mem);
virtual ~File2MemR(void);
bool isGood(void) override;
bool write(const ByteSpan data, int64_t pos = -1) override;
std::variant<ByteSpan, std::vector<uint8_t>> read(uint64_t size, int64_t pos = -1) override;
};