GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 of 18, 0 excluded
0.0%
Functions:
0 of 2, 0 excluded
0.0%
Branches:
0 of 26, 0 excluded
0.0%

libs/base/src/base/memorychunk.cc
Line Branch Exec Source
1 #include "base/memorychunk.h"
2
3 #include <fstream>
4
5 namespace eu
6 {
7
8 MemoryChunkData::operator MemoryChunk() const
9 {
10 return {.bytes = bytes.data(), .size = bytes.size() };
11 }
12
13
14
15 MemoryChunkData chunk_from_file(const std::string& full_path)
16 {
17 std::ifstream is(full_path, std::ifstream::binary);
18 if(!is)
19 {
20 LOG_ERR("Failed to read real file {}", full_path);
21 return {};
22 }
23
24 is.seekg(0, std::ifstream::end);
25 const auto length = is.tellg();
26 is.seekg(0, std::ifstream::beg);
27
28 if(length <= 0)
29 {
30 LOG_ERR("File empty: {}", full_path);
31 return {};
32 }
33
34 MemoryChunkData memory;
35 memory.bytes.resize(length);
36 is.read
37 (
38 memory.bytes.data(),
39 length
40 );
41
42 return memory;
43 }
44
45 }
46