diff --git a/cores/esp8266/FS.cpp b/cores/esp8266/FS.cpp index 6ae11e1782..90de4f3c4c 100644 --- a/cores/esp8266/FS.cpp +++ b/cores/esp8266/FS.cpp @@ -121,6 +121,21 @@ const char* File::name() const { return _p->name(); } +String File::readString() +{ + String ret; + ret.reserve(size() - position()); + char temp[256+1]; + int countRead = readBytes(temp, sizeof(temp)-1); + while (countRead > 0) + { + temp[countRead] = 0; + ret += temp; + countRead = readBytes(temp, sizeof(temp)-1); + } + return ret; +} + File Dir::openFile(const char* mode) { if (!_impl) { return File(); diff --git a/cores/esp8266/FS.h b/cores/esp8266/FS.h index 79620f96c8..3cf34bb746 100644 --- a/cores/esp8266/FS.h +++ b/cores/esp8266/FS.h @@ -72,7 +72,8 @@ class File : public Stream void close(); operator bool() const; const char* name() const; - + String readString() override; + protected: FileImplPtr _p; }; diff --git a/cores/esp8266/Stream.h b/cores/esp8266/Stream.h index 290971cf42..fa786dddc3 100644 --- a/cores/esp8266/Stream.h +++ b/cores/esp8266/Stream.h @@ -101,7 +101,7 @@ class Stream: public Print { // returns the number of characters placed in the buffer (0 means no valid data found) // Arduino String functions to be added here - String readString(); + virtual String readString(); String readStringUntil(char terminator); protected: