small file improvements

This commit is contained in:
Green Sky 2023-08-21 21:24:10 +02:00
parent 53d65a0685
commit 15c627451d
No known key found for this signature in database

View File

@ -37,13 +37,6 @@ struct FileRWFile : public FileI {
// TODO: error check // TODO: error check
_file.seekg(pos, std::ios::beg); _file.seekg(pos, std::ios::beg);
#if 0
std::vector<uint8_t> chunk;
int read_char;
for (size_t i = 0; i < size && (_file_size == 0 || i+pos < _file_size) && (read_char = _file.get()) != std::ifstream::traits_type::eof(); i++) {
chunk.push_back(read_char);
}
#else
std::vector<uint8_t> chunk(size); std::vector<uint8_t> chunk(size);
const auto nread = _file.read(reinterpret_cast<char*>(chunk.data()), chunk.size()).gcount(); const auto nread = _file.read(reinterpret_cast<char*>(chunk.data()), chunk.size()).gcount();
if (nread != std::numeric_limits<std::streamsize>::max()) { if (nread != std::numeric_limits<std::streamsize>::max()) {
@ -51,7 +44,6 @@ struct FileRWFile : public FileI {
} else { } else {
chunk.clear(); chunk.clear();
} }
#endif
_bytes_read += chunk.size(); _bytes_read += chunk.size();
@ -66,7 +58,9 @@ 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, std::ios::beg); if (_file.seekp(pos, std::ios::beg).fail()) {
return false;
}
} }
_file.write(reinterpret_cast<const char*>(data.data()), data.size()); _file.write(reinterpret_cast<const char*>(data.data()), data.size());