From 7b04c193ca3dc48208ee1f0e538c6a6313a2adaa Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 18 Jul 2014 21:01:51 +0200 Subject: [PATCH] [DEV] add simple file reader --- etk/os/FSNode.cpp | 16 ++++++++++++++++ etk/os/FSNode.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/etk/os/FSNode.cpp b/etk/os/FSNode.cpp index 136743a..a71e88c 100644 --- a/etk/os/FSNode.cpp +++ b/etk/os/FSNode.cpp @@ -2015,3 +2015,19 @@ void etk::FSNodeHistory(const std::string& _path, int32_t _historyCount) { void etk::FSNodeHistory(const std::u32string& _path, int32_t _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; +} diff --git a/etk/os/FSNode.h b/etk/os/FSNode.h index b048eab..51cf298 100644 --- a/etk/os/FSNode.h +++ b/etk/os/FSNode.h @@ -673,6 +673,12 @@ namespace etk { */ void FSNodeHistory(const std::string& _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