New function to read files whose size is not known beforehand

(cherry picked from commit 4a9ef9cb8ddcbe075a90000c411db131ad39033b)
This commit is contained in:
Martin 2016-11-18 02:42:50 +01:00
parent 8fdb2f0568
commit 593e762e90
2 changed files with 17 additions and 1 deletions

View File

@ -218,6 +218,22 @@ std::string getFile(std::string filename)
return ret;
}
std::string getStreamFile(const std::string& fn)
{
std::fstream fin(fn.c_str(), std::ios::binary | std::ios::in);
if (!fin.is_open())
return std::string();
std::string ret;
while (!fin.eof())
{
char buf[512];
fin.read(buf, sizeof(buf));
ret.insert(ret.end(), buf, buf + fin.gcount());
}
return ret;
}
void strupper_utf8(std::string *pStr)
{
std::wstring tmp;

View File

@ -22,7 +22,7 @@ std::string getuntilinc(std::string str,std::string data);
std::string getline(int line,const std::string &str);
int linecount(const std::string &str);
std::string getFile(std::string filename);
std::string getFileUTF8(std::string filename);
std::string getStreamFile(const std::string& fn);
std::string ExtractFileName(std::string fulln, std::string separators="/\\");
std::string ExtractFilePath(std::string fulln, std::string separators="/\\");
std::string convert(bool pBool);