| 8 | namespace mdf::detail { |
| 9 | |
| 10 | uint64_t DataBlock::CopyDataToFile(std::streambuf& from_file, |
| 11 | std::streambuf& to_file) const { |
| 12 | SetFilePosition(from_file, DataPosition()); |
| 13 | |
| 14 | uint64_t data_size = DataSize(); |
| 15 | if (data_size == 0) { |
| 16 | return 0; |
| 17 | } |
| 18 | uint64_t count = 0; |
| 19 | std::array<char, 10'000> temp{}; |
| 20 | uint64_t bytes_to_read = std::min(data_size, static_cast<uint64_t>(temp.size()) ); |
| 21 | for (uint64_t reads = from_file.sgetn(temp.data(), |
| 22 | static_cast<std::streamsize>(bytes_to_read)); |
| 23 | reads > 0 && bytes_to_read > 0 && data_size > 0; |
| 24 | reads = from_file.sgetn(temp.data(), |
| 25 | static_cast<std::streamsize>(bytes_to_read) )) { |
| 26 | const uint64_t writes = to_file.sputn(temp.data(), |
| 27 | static_cast<std::streamsize>(reads)); |
| 28 | count += writes; |
| 29 | if (writes != reads) { |
| 30 | break; |
| 31 | } |
| 32 | |
| 33 | data_size -= reads; |
| 34 | bytes_to_read = std::min(data_size, static_cast<uint64_t>(temp.size()) ); |
| 35 | } |
| 36 | return count; |
| 37 | } |
| 38 | |
| 39 | uint64_t DataBlock::CopyDataToBuffer(std::streambuf& buffer, |
| 40 | std::vector<uint8_t> &dest, |
nothing calls this directly
no test coverage detected