MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / readToVector

Function readToVector

test/api/APIUnitTest.cpp:442–456  ·  view source on GitHub ↗

Helper function to read file into a buffer.

Source from the content-addressed store, hash-verified

440
441// Helper function to read file into a buffer.
442bool readToVector(const char *Path, std::vector<uint8_t> &Buf) {
443 std::ifstream F(Path, std::ios::binary | std::ios::ate);
444 if (!F) {
445 return false;
446 }
447 F.seekg(0, std::ios::end);
448 Buf.resize(static_cast<uint32_t>(F.tellg()));
449 F.seekg(0, std::ios::beg);
450 if (!F.read(reinterpret_cast<char *>(Buf.data()),
451 static_cast<uint32_t>(Buf.size()))) {
452 return false;
453 }
454 F.close();
455 return true;
456}
457
458// Helper function to check error code.
459bool isErrMatch(WasmEdge_ErrCode Err, WasmEdge_Result Res) {

Callers 1

TESTFunction · 0.85

Calls 6

resizeMethod · 0.80
tellgMethod · 0.80
readMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected