[DEV] add simple file reader

This commit is contained in:
Edouard DUPIN 2014-07-18 21:01:51 +02:00
parent 7c41031ee0
commit 7b04c193ca
2 changed files with 22 additions and 0 deletions

View File

@ -2015,3 +2015,19 @@ void etk::FSNodeHistory(const std::string& _path, int32_t _historyCount) {
void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) { void etk::FSNodeHistory(const std::u32string& _path, int32_t _historyCount) {
return FSNodeHistory(std::to_string(_path), _historyCount); return FSNodeHistory(std::to_string(_path), _historyCount);
} }
std::string etk::FSNodeReadAllData(const std::string& _path) {
std::string output;
etk::FSNode node(_path);
if (node.fileOpenRead() == false) {
TK_ERROR("can not open file : '" << node << "'");
return "";
}
std::string tmp;
while (node.fileGets(tmp) == true) {
output += tmp;
}
output += tmp;
node.fileClose();
return output;
}

View File

@ -673,6 +673,12 @@ namespace etk {
*/ */
void FSNodeHistory(const std::string& _path, int32_t _historyCount); void FSNodeHistory(const std::string& _path, int32_t _historyCount);
void FSNodeHistory(const std::u32string& _path, int32_t _historyCount); void FSNodeHistory(const std::u32string& _path, int32_t _historyCount);
/**
* @brief Read all the data from a file
* @param[in] _path Folder/File/Pipe path of the node
* @return all the data of the file in a string
*/
std::string FSNodeReadAllData(const std::string& _path);
}; };
#endif #endif