MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / readFile

Function readFile

Source/Internal/filesystem.cpp:695–748  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

693}
694
695vector<unsigned char> readFile(const char* filename) {
696 /*
697 TODO: Fix this faster variant
698 vector<unsigned char> vec;
699 ifstream in(filename, ios::in | ios::binary);
700 if (in)
701 {
702 string contents;
703 in.seekg(0, ios::end);
704 vec.resize(in.tellg());
705 in.seekg(0, ios::beg);
706 in.read(&contents[0], contents.size());
707 in.close();
708 }
709 else
710 {
711 LOGF << "Unable to read file" << filename << endl;
712 }
713 return vec;
714 */
715
716 // open the file:
717 vector<unsigned char> vec;
718
719 if (isFile(filename)) {
720 ifstream file;
721 my_ifstream_open(file, filename, ios::binary);
722
723 if (file.good()) {
724 // Stop eating new lines in binary mode!!!
725 file.unsetf(ios::skipws);
726
727 // get its size:
728 streampos fileSize;
729
730 file.seekg(0, ios::end);
731 fileSize = file.tellg();
732 file.seekg(0, ios::beg);
733
734 // reserve capacity
735 vec.reserve(fileSize);
736
737 // read the data:
738 vec.insert(vec.begin(),
739 istream_iterator<unsigned char>(file),
740 istream_iterator<unsigned char>());
741 } else {
742 LOGE << "Unable to read file " << filename << endl;
743 }
744 file.close();
745 }
746
747 return vec;
748}
749
750void CreateParentDirs(const string& abs_path) {
751 CreateParentDirs(abs_path.c_str());

Callers 7

LoadLevelFunction · 0.85
RibbonItemClickedMethod · 0.85
GetFileHashFunction · 0.85
DrawObjectInfoFlatFunction · 0.85
DrawBrowsePathFunction · 0.85
DrawImGuiFunction · 0.85
GetUserPickedReadPathFunction · 0.85

Calls 6

my_ifstream_openFunction · 0.85
isFileFunction · 0.50
reserveMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected