get file rw working
This commit is contained in:
parent
c73e429df1
commit
53d65a0685
@ -8,13 +8,20 @@
|
|||||||
struct FileRWFile : public FileI {
|
struct FileRWFile : public FileI {
|
||||||
std::fstream _file;
|
std::fstream _file;
|
||||||
|
|
||||||
//FileWFile(std::string_view file_path, uint64_t file_size) : _file(static_cast<std::string>(file_path), std::ios::binary) {
|
// dont truncate by default
|
||||||
//_file_size = file_size;
|
FileRWFile(std::string_view file_path, uint64_t file_size, bool trunc = false)
|
||||||
|
: _file(
|
||||||
|
static_cast<std::string>(file_path),
|
||||||
|
std::ios::in |
|
||||||
|
std::ios::out |
|
||||||
|
(trunc ? std::ios::trunc | std::ios::binary : std::ios::binary) // hacky but type safe
|
||||||
|
) {
|
||||||
|
_file_size = file_size;
|
||||||
|
|
||||||
//if (!_file.is_open()) {
|
if (!_file.is_open()) {
|
||||||
//return; // TODO: error
|
return; // TODO: error
|
||||||
//}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
virtual ~FileRWFile(void) {}
|
virtual ~FileRWFile(void) {}
|
||||||
|
|
||||||
@ -28,7 +35,7 @@ struct FileRWFile : public FileI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: error check
|
// TODO: error check
|
||||||
_file.seekg(pos);
|
_file.seekg(pos, std::ios::beg);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
std::vector<uint8_t> chunk;
|
std::vector<uint8_t> chunk;
|
||||||
@ -59,7 +66,7 @@ struct FileRWFile : public FileI {
|
|||||||
// if out-of-order, seek
|
// if out-of-order, seek
|
||||||
if (_file.tellp() != int64_t(pos)) {
|
if (_file.tellp() != int64_t(pos)) {
|
||||||
// TODO: error check
|
// TODO: error check
|
||||||
_file.seekp(pos);
|
_file.seekp(pos, std::ios::beg);
|
||||||
}
|
}
|
||||||
|
|
||||||
_file.write(reinterpret_cast<const char*>(data.data()), data.size());
|
_file.write(reinterpret_cast<const char*>(data.data()), data.size());
|
||||||
|
Loading…
Reference in New Issue
Block a user