MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / file_to_buffer

Function file_to_buffer

nanofi/src/api/nanofi.cpp:46–75  ·  view source on GitHub ↗

Just an internal utility func., not to be published via API!

Source from the content-addressed store, hash-verified

44
45// Just an internal utility func., not to be published via API!
46file_buffer file_to_buffer(const char *path) {
47 file_buffer fb;
48 fb.buffer = nullptr;
49 fb.file_len = 0;
50
51 NULL_CHECK(fb, path);
52 FILE *fileptr;
53 uint8_t *buffer;
54 size_t filelen;
55
56 fileptr = fopen(path, "rb");
57 NULL_CHECK(fb, fileptr);
58
59 fseek(fileptr, 0, SEEK_END);
60 filelen = ftell(fileptr);
61 rewind(fileptr);
62
63 buffer = (uint8_t *)malloc((filelen+1)*sizeof(uint8_t)); // Enough memory for file + \0
64 const size_t read_result = fread(buffer, filelen, 1, fileptr);
65 fclose(fileptr);
66
67 if (read_result != 1) {
68 free(buffer);
69 return fb;
70 }
71
72 fb.buffer = buffer;
73 fb.file_len = filelen;
74 return fb;
75}
76
77int API_INITIALIZER::initialized = initialize_api();
78

Callers 4

get_contentFunction · 0.85
transmit_flowfileFunction · 0.85
invoke_ffFunction · 0.85
invoke_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected