MCPcopy Create free account
hub / github.com/creatale/node-dv / LoadDataFromFile

Function LoadDataFromFile

deps/tesseract/ccutil/genericvector.h:359–376  ·  view source on GitHub ↗

The default FileReader loads the whole file into the vector of char, returning false on error.

Source from the content-addressed store, hash-verified

357// The default FileReader loads the whole file into the vector of char,
358// returning false on error.
359inline bool LoadDataFromFile(const STRING& filename,
360 GenericVector<char>* data) {
361 bool result = false;
362 FILE* fp = fopen(filename.string(), "rb");
363 if (fp != NULL) {
364 fseek(fp, 0, SEEK_END);
365 size_t size = ftell(fp);
366 fseek(fp, 0, SEEK_SET);
367 if (size > 0) {
368 // reserve an extra byte in case caller wants to append a '\0' character
369 data->reserve(size + 1);
370 data->resize_no_init(size);
371 result = fread(&(*data)[0], 1, size, fp) == size;
372 }
373 fclose(fp);
374 }
375 return result;
376}
377// The default FileWriter writes the vector of char to the filename file,
378// returning false on error.
379inline bool SaveDataToFile(const GenericVector<char>& data,

Callers 2

ReadAllBoxesFunction · 0.85
OpenMethod · 0.85

Calls 3

resize_no_initMethod · 0.80
stringMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected