mirror of https://github.com/kiwix/libkiwix.git
Add a function to get the content of a file.
This commit is contained in:
parent
2164faba44
commit
9f86b59d1d
|
@ -51,6 +51,7 @@ string appendToDirectory(const string& directoryPath, const string& filename);
|
|||
|
||||
unsigned int getFileSize(const string& path);
|
||||
string getFileSizeAsString(const string& path);
|
||||
string getFileContent(const string& path);
|
||||
bool fileExists(const string& path);
|
||||
bool makeDirectory(const string& path);
|
||||
bool copyFile(const string& sourcePath, const string& destPath);
|
||||
|
|
|
@ -188,6 +188,20 @@ string getFileSizeAsString(const string& path)
|
|||
return convert.str();
|
||||
}
|
||||
|
||||
string getFileContent(const string& path)
|
||||
{
|
||||
std::ifstream f(path, std::ios::in|std::ios::ate);
|
||||
std::string content;
|
||||
if (f.is_open()) {
|
||||
auto size = f.tellg();
|
||||
content.reserve(size);
|
||||
f.seekg(0, std::ios::beg);
|
||||
content.assign((std::istreambuf_iterator<char>(f)),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
bool fileExists(const string& path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
Loading…
Reference in New Issue