MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / ReadData

Method ReadData

lib/mdflib/mdflib/src/at4block.cpp:230–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230void 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
267void At4Block::ReadData(std::streambuf& buffer,
268 std::streambuf& dest_buffer) const {

Callers

nothing calls this directly

Calls 9

SetFilePositionFunction · 0.85
failureFunction · 0.85
InflateFunction · 0.85
CopyBytesFunction · 0.85
CreateMd5FileChecksumFunction · 0.85
is_openMethod · 0.80
openMethod · 0.45
closeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected