| 228 | } |
| 229 | |
| 230 | void At4Block::ReadData(std::streambuf& buffer, |
| 231 | const std::string& dest_file) const { |
| 232 | if (data_position_ <= 0) { |
| 233 | throw std::invalid_argument("File is not opened or data position not read"); |
| 234 | } |
| 235 | SetFilePosition(buffer, data_position_); |
| 236 | if (IsEmbedded()) { |
| 237 | std::filebuf dest; |
| 238 | dest.open( dest_file, |
| 239 | std::ios_base::out | std::ios_base::trunc | std::ios_base::binary); |
| 240 | if (!dest.is_open()) { |
| 241 | throw std::ios_base::failure("Failed to open the destination file"); |
| 242 | } |
| 243 | const bool error = IsCompressed() ? !Inflate(buffer, dest, nof_bytes_) |
| 244 | : !CopyBytes(buffer, dest, nof_bytes_); |
| 245 | dest.close(); |
| 246 | if ( error ) { |
| 247 | throw std::ios_base::failure("Failed to copy correct number of bytes"); |
| 248 | } |
| 249 | } else { |
| 250 | // Need to copy the source file |
| 251 | fs::path s = fs::u8path(filename_); |
| 252 | fs::path d = fs::u8path(dest_file); |
| 253 | if (s != d) { |
| 254 | fs::copy_file( |
| 255 | s, d, fs::copy_options::overwrite_existing); |
| 256 | } |
| 257 | } |
| 258 | if (flags_ & At4Flags::kUsingMd5) { |
| 259 | std::vector<uint8_t> md5(16, 0xFF); |
| 260 | CreateMd5FileChecksum(dest_file, md5); |
| 261 | if (md5 != md5_) { |
| 262 | throw std::runtime_error("Mismatching MD5 checksums"); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | void At4Block::ReadData(std::streambuf& buffer, |
| 268 | std::streambuf& dest_buffer) const { |
nothing calls this directly
no test coverage detected